Fossil SCM

Fix a typo in the CGI extension documentation.

drh 2019-09-26 17:36 trunk
Commit b4ac00d8bb7ad36219f4fe71f3bfa6b62114e5c53fb652fd71ebb281274fe3b9
+199 -159
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1165,11 +1165,11 @@
11651165
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11661166
** [sqlite_version()] and [sqlite_source_id()].
11671167
*/
11681168
#define SQLITE_VERSION "3.30.0"
11691169
#define SQLITE_VERSION_NUMBER 3030000
1170
-#define SQLITE_SOURCE_ID "2019-09-21 17:31:03 8ea1dc727d391b15d0c4fa858ff68d5b8a63dde46408f24027dac8d28f044cbd"
1170
+#define SQLITE_SOURCE_ID "2019-09-26 16:57:42 49073b7003330027303c4c776e9f85112f8b99b89f848fec3f953eba501d7505"
11711171
11721172
/*
11731173
** CAPI3REF: Run-Time Library Version Numbers
11741174
** KEYWORDS: sqlite3_version sqlite3_sourceid
11751175
**
@@ -19349,11 +19349,10 @@
1934919349
#ifndef SQLITE_AMALGAMATION
1935019350
SQLITE_PRIVATE const unsigned char sqlite3OpcodeProperty[];
1935119351
SQLITE_PRIVATE const char sqlite3StrBINARY[];
1935219352
SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[];
1935319353
SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[];
19354
-SQLITE_PRIVATE const Token sqlite3IntTokens[];
1935519354
SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config;
1935619355
SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions;
1935719356
#ifndef SQLITE_OMIT_WSD
1935819357
SQLITE_PRIVATE int sqlite3PendingByte;
1935919358
#endif
@@ -20020,18 +20019,10 @@
2002020019
** database connections. After initialization, this table is
2002120020
** read-only.
2002220021
*/
2002320022
SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions;
2002420023
20025
-/*
20026
-** Constant tokens for values 0 and 1.
20027
-*/
20028
-SQLITE_PRIVATE const Token sqlite3IntTokens[] = {
20029
- { "0", 1 },
20030
- { "1", 1 }
20031
-};
20032
-
2003320024
#ifdef VDBE_PROFILE
2003420025
/*
2003520026
** The following performance counter can be used in place of
2003620027
** sqlite3Hwtime() for profiling. This is a no-op on standard builds.
2003720028
*/
@@ -38509,11 +38500,11 @@
3850938500
** as the associated database file.
3851038501
**
3851138502
** If the SQLITE_ENABLE_8_3_NAMES option is enabled, then the
3851238503
** original filename is unavailable. But 8_3_NAMES is only used for
3851338504
** FAT filesystems and permissions do not matter there, so just use
38514
-** the default permissions.
38505
+** the default permissions. In 8_3_NAMES mode, leave *pMode set to zero.
3851538506
*/
3851638507
static int findCreateFileMode(
3851738508
const char *zPath, /* Path of file (possibly) being created */
3851838509
int flags, /* Flags passed as 4th argument to xOpen() */
3851938510
mode_t *pMode, /* OUT: Permissions to open file with */
@@ -38744,15 +38735,23 @@
3874438735
int rc2 = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zName);
3874538736
if( rc==SQLITE_OK ) rc = rc2;
3874638737
goto open_finished;
3874738738
}
3874838739
38749
- /* If this process is running as root and if creating a new rollback
38750
- ** journal or WAL file, set the ownership of the journal or WAL to be
38751
- ** the same as the original database.
38740
+ /* The owner of the rollback journal or WAL file should always be the
38741
+ ** same as the owner of the database file. Try to ensure that this is
38742
+ ** the case. The chown() system call will be a no-op if the current
38743
+ ** process lacks root privileges, be we should at least try. Without
38744
+ ** this step, if a root process opens a database file, it can leave
38745
+ ** behinds a journal/WAL that is owned by root and hence make the
38746
+ ** database inaccessible to unprivileged processes.
38747
+ **
38748
+ ** If openMode==0, then that means uid and gid are not set correctly
38749
+ ** (probably because SQLite is configured to use 8+3 filename mode) and
38750
+ ** in that case we do not want to attempt the chown().
3875238751
*/
38753
- if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){
38752
+ if( openMode && (flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL))!=0 ){
3875438753
robustFchown(fd, uid, gid);
3875538754
}
3875638755
}
3875738756
assert( fd>=0 );
3875838757
if( pOutFlags ){
@@ -95757,10 +95756,17 @@
9575795756
memcpy(pExpr, pDup, sizeof(*pExpr));
9575895757
if( !ExprHasProperty(pExpr, EP_IntValue) && pExpr->u.zToken!=0 ){
9575995758
assert( (pExpr->flags & (EP_Reduced|EP_TokenOnly))==0 );
9576095759
pExpr->u.zToken = sqlite3DbStrDup(db, pExpr->u.zToken);
9576195760
pExpr->flags |= EP_MemToken;
95761
+ }
95762
+ if( ExprHasProperty(pExpr, EP_WinFunc) ){
95763
+ if( pExpr->y.pWin!=0 ){
95764
+ pExpr->y.pWin->pOwner = pExpr;
95765
+ }else{
95766
+ assert( db->mallocFailed );
95767
+ }
9576295768
}
9576395769
sqlite3DbFree(db, pDup);
9576495770
}
9576595771
ExprSetProperty(pExpr, EP_Alias);
9576695772
}
@@ -98388,11 +98394,11 @@
9838898394
}else if( pRight==0 ){
9838998395
return pLeft;
9839098396
}else if( ExprAlwaysFalse(pLeft) || ExprAlwaysFalse(pRight) ){
9839198397
sqlite3ExprUnmapAndDelete(pParse, pLeft);
9839298398
sqlite3ExprUnmapAndDelete(pParse, pRight);
98393
- return sqlite3ExprAlloc(db, TK_INTEGER, &sqlite3IntTokens[0], 0);
98399
+ return sqlite3Expr(db, TK_INTEGER, "0");
9839498400
}else{
9839598401
return sqlite3PExpr(pParse, TK_AND, pLeft, pRight);
9839698402
}
9839798403
}
9839898404
@@ -100442,15 +100448,25 @@
100442100448
}else{
100443100449
dest.eDest = SRT_Exists;
100444100450
sqlite3VdbeAddOp2(v, OP_Integer, 0, dest.iSDParm);
100445100451
VdbeComment((v, "Init EXISTS result"));
100446100452
}
100447
- pLimit = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[1], 0);
100448100453
if( pSel->pLimit ){
100449
- sqlite3ExprDelete(pParse->db, pSel->pLimit->pLeft);
100454
+ /* The subquery already has a limit. If the pre-existing limit is X
100455
+ ** then make the new limit X<>0 so that the new limit is either 1 or 0 */
100456
+ sqlite3 *db = pParse->db;
100457
+ pLimit = sqlite3Expr(db, TK_INTEGER, "0");
100458
+ if( pLimit ){
100459
+ pLimit->affExpr = SQLITE_AFF_NUMERIC;
100460
+ pLimit = sqlite3PExpr(pParse, TK_NE,
100461
+ sqlite3ExprDup(db, pSel->pLimit->pLeft, 0), pLimit);
100462
+ }
100463
+ sqlite3ExprDelete(db, pSel->pLimit->pLeft);
100450100464
pSel->pLimit->pLeft = pLimit;
100451100465
}else{
100466
+ /* If there is no pre-existing limit add a limit of 1 */
100467
+ pLimit = sqlite3Expr(pParse->db, TK_INTEGER, "1");
100452100468
pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0);
100453100469
}
100454100470
pSel->iLimit = 0;
100455100471
if( sqlite3Select(pParse, pSel, &dest) ){
100456100472
return 0;
@@ -131029,11 +131045,11 @@
131029131045
static int havingToWhereExprCb(Walker *pWalker, Expr *pExpr){
131030131046
if( pExpr->op!=TK_AND ){
131031131047
Select *pS = pWalker->u.pSelect;
131032131048
if( sqlite3ExprIsConstantOrGroupBy(pWalker->pParse, pExpr, pS->pGroupBy) ){
131033131049
sqlite3 *db = pWalker->pParse->db;
131034
- Expr *pNew = sqlite3ExprAlloc(db, TK_INTEGER, &sqlite3IntTokens[1], 0);
131050
+ Expr *pNew = sqlite3Expr(db, TK_INTEGER, "1");
131035131051
if( pNew ){
131036131052
Expr *pWhere = pS->pWhere;
131037131053
SWAP(Expr, *pNew, *pExpr);
131038131054
pNew = sqlite3ExprAnd(pWalker->pParse, pWhere, pNew);
131039131055
pS->pWhere = pNew;
@@ -147627,11 +147643,11 @@
147627147643
** that pSublist is still NULL here. Add a constant expression here to
147628147644
** keep everything legal in this case.
147629147645
*/
147630147646
if( pSublist==0 ){
147631147647
pSublist = sqlite3ExprListAppend(pParse, 0,
147632
- sqlite3ExprAlloc(db, TK_INTEGER, &sqlite3IntTokens[0], 0)
147648
+ sqlite3Expr(db, TK_INTEGER, "0")
147633147649
);
147634147650
}
147635147651
147636147652
pSub = sqlite3SelectNew(
147637147653
pParse, pSublist, pSrc, pWhere, pGroupBy, pHaving, pSort, 0, 0
@@ -148044,124 +148060,10 @@
148044148060
static int windowArgCount(Window *pWin){
148045148061
ExprList *pList = pWin->pOwner->x.pList;
148046148062
return (pList ? pList->nExpr : 0);
148047148063
}
148048148064
148049
-/*
148050
-** Generate VM code to invoke either xStep() (if bInverse is 0) or
148051
-** xInverse (if bInverse is non-zero) for each window function in the
148052
-** linked list starting at pMWin. Or, for built-in window functions
148053
-** that do not use the standard function API, generate the required
148054
-** inline VM code.
148055
-**
148056
-** If argument csr is greater than or equal to 0, then argument reg is
148057
-** the first register in an array of registers guaranteed to be large
148058
-** enough to hold the array of arguments for each function. In this case
148059
-** the arguments are extracted from the current row of csr into the
148060
-** array of registers before invoking OP_AggStep or OP_AggInverse
148061
-**
148062
-** Or, if csr is less than zero, then the array of registers at reg is
148063
-** already populated with all columns from the current row of the sub-query.
148064
-**
148065
-** If argument regPartSize is non-zero, then it is a register containing the
148066
-** number of rows in the current partition.
148067
-*/
148068
-static void windowAggStep(
148069
- Parse *pParse,
148070
- Window *pMWin, /* Linked list of window functions */
148071
- int csr, /* Read arguments from this cursor */
148072
- int bInverse, /* True to invoke xInverse instead of xStep */
148073
- int reg /* Array of registers */
148074
-){
148075
- Vdbe *v = sqlite3GetVdbe(pParse);
148076
- Window *pWin;
148077
- for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
148078
- FuncDef *pFunc = pWin->pFunc;
148079
- int regArg;
148080
- int nArg = pWin->bExprArgs ? 0 : windowArgCount(pWin);
148081
- int i;
148082
-
148083
- assert( bInverse==0 || pWin->eStart!=TK_UNBOUNDED );
148084
-
148085
- for(i=0; i<nArg; i++){
148086
- if( i!=1 || pFunc->zName!=nth_valueName ){
148087
- sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+i, reg+i);
148088
- }else{
148089
- sqlite3VdbeAddOp3(v, OP_Column, pMWin->iEphCsr, pWin->iArgCol+i, reg+i);
148090
- }
148091
- }
148092
- regArg = reg;
148093
-
148094
- if( pMWin->regStartRowid==0
148095
- && (pFunc->funcFlags & SQLITE_FUNC_MINMAX)
148096
- && (pWin->eStart!=TK_UNBOUNDED)
148097
- ){
148098
- int addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, regArg);
148099
- VdbeCoverage(v);
148100
- if( bInverse==0 ){
148101
- sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1, 1);
148102
- sqlite3VdbeAddOp2(v, OP_SCopy, regArg, pWin->regApp);
148103
- sqlite3VdbeAddOp3(v, OP_MakeRecord, pWin->regApp, 2, pWin->regApp+2);
148104
- sqlite3VdbeAddOp2(v, OP_IdxInsert, pWin->csrApp, pWin->regApp+2);
148105
- }else{
148106
- sqlite3VdbeAddOp4Int(v, OP_SeekGE, pWin->csrApp, 0, regArg, 1);
148107
- VdbeCoverageNeverTaken(v);
148108
- sqlite3VdbeAddOp1(v, OP_Delete, pWin->csrApp);
148109
- sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
148110
- }
148111
- sqlite3VdbeJumpHere(v, addrIsNull);
148112
- }else if( pWin->regApp ){
148113
- assert( pFunc->zName==nth_valueName
148114
- || pFunc->zName==first_valueName
148115
- );
148116
- assert( bInverse==0 || bInverse==1 );
148117
- sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1-bInverse, 1);
148118
- }else if( pFunc->xSFunc!=noopStepFunc ){
148119
- int addrIf = 0;
148120
- if( pWin->pFilter ){
148121
- int regTmp;
148122
- assert( pWin->bExprArgs || !nArg ||nArg==pWin->pOwner->x.pList->nExpr );
148123
- assert( pWin->bExprArgs || nArg ||pWin->pOwner->x.pList==0 );
148124
- regTmp = sqlite3GetTempReg(pParse);
148125
- sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+nArg,regTmp);
148126
- addrIf = sqlite3VdbeAddOp3(v, OP_IfNot, regTmp, 0, 1);
148127
- VdbeCoverage(v);
148128
- sqlite3ReleaseTempReg(pParse, regTmp);
148129
- }
148130
- if( pWin->bExprArgs ){
148131
- int iStart = sqlite3VdbeCurrentAddr(v);
148132
- VdbeOp *pOp, *pEnd;
148133
-
148134
- nArg = pWin->pOwner->x.pList->nExpr;
148135
- regArg = sqlite3GetTempRange(pParse, nArg);
148136
- sqlite3ExprCodeExprList(pParse, pWin->pOwner->x.pList, regArg, 0, 0);
148137
-
148138
- pEnd = sqlite3VdbeGetOp(v, -1);
148139
- for(pOp=sqlite3VdbeGetOp(v, iStart); pOp<=pEnd; pOp++){
148140
- if( pOp->opcode==OP_Column && pOp->p1==pWin->iEphCsr ){
148141
- pOp->p1 = csr;
148142
- }
148143
- }
148144
- }
148145
- if( pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
148146
- CollSeq *pColl;
148147
- assert( nArg>0 );
148148
- pColl = sqlite3ExprNNCollSeq(pParse, pWin->pOwner->x.pList->a[0].pExpr);
148149
- sqlite3VdbeAddOp4(v, OP_CollSeq, 0,0,0, (const char*)pColl, P4_COLLSEQ);
148150
- }
148151
- sqlite3VdbeAddOp3(v, bInverse? OP_AggInverse : OP_AggStep,
148152
- bInverse, regArg, pWin->regAccum);
148153
- sqlite3VdbeAppendP4(v, pFunc, P4_FUNCDEF);
148154
- sqlite3VdbeChangeP5(v, (u8)nArg);
148155
- if( pWin->bExprArgs ){
148156
- sqlite3ReleaseTempRange(pParse, regArg, nArg);
148157
- }
148158
- if( addrIf ) sqlite3VdbeJumpHere(v, addrIf);
148159
- }
148160
- }
148161
-}
148162
-
148163148065
typedef struct WindowCodeArg WindowCodeArg;
148164148066
typedef struct WindowCsrAndReg WindowCsrAndReg;
148165148067
148166148068
/*
148167148069
** See comments above struct WindowCodeArg.
@@ -148238,17 +148140,10 @@
148238148140
WindowCsrAndReg start;
148239148141
WindowCsrAndReg current;
148240148142
WindowCsrAndReg end;
148241148143
};
148242148144
148243
-/*
148244
-** Values that may be passed as the second argument to windowCodeOp().
148245
-*/
148246
-#define WINDOW_RETURN_ROW 1
148247
-#define WINDOW_AGGINVERSE 2
148248
-#define WINDOW_AGGSTEP 3
148249
-
148250148145
/*
148251148146
** Generate VM code to read the window frames peer values from cursor csr into
148252148147
** an array of registers starting at reg.
148253148148
*/
148254148149
static void windowReadPeerValues(
@@ -148267,10 +148162,137 @@
148267148162
sqlite3VdbeAddOp3(v, OP_Column, csr, iColOff+i, reg+i);
148268148163
}
148269148164
}
148270148165
}
148271148166
148167
+/*
148168
+** Generate VM code to invoke either xStep() (if bInverse is 0) or
148169
+** xInverse (if bInverse is non-zero) for each window function in the
148170
+** linked list starting at pMWin. Or, for built-in window functions
148171
+** that do not use the standard function API, generate the required
148172
+** inline VM code.
148173
+**
148174
+** If argument csr is greater than or equal to 0, then argument reg is
148175
+** the first register in an array of registers guaranteed to be large
148176
+** enough to hold the array of arguments for each function. In this case
148177
+** the arguments are extracted from the current row of csr into the
148178
+** array of registers before invoking OP_AggStep or OP_AggInverse
148179
+**
148180
+** Or, if csr is less than zero, then the array of registers at reg is
148181
+** already populated with all columns from the current row of the sub-query.
148182
+**
148183
+** If argument regPartSize is non-zero, then it is a register containing the
148184
+** number of rows in the current partition.
148185
+*/
148186
+static void windowAggStep(
148187
+ WindowCodeArg *p,
148188
+ Window *pMWin, /* Linked list of window functions */
148189
+ int csr, /* Read arguments from this cursor */
148190
+ int bInverse, /* True to invoke xInverse instead of xStep */
148191
+ int reg /* Array of registers */
148192
+){
148193
+ Parse *pParse = p->pParse;
148194
+ Vdbe *v = sqlite3GetVdbe(pParse);
148195
+ Window *pWin;
148196
+ for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
148197
+ FuncDef *pFunc = pWin->pFunc;
148198
+ int regArg;
148199
+ int nArg = pWin->bExprArgs ? 0 : windowArgCount(pWin);
148200
+ int i;
148201
+
148202
+ assert( bInverse==0 || pWin->eStart!=TK_UNBOUNDED );
148203
+
148204
+ /* All OVER clauses in the same window function aggregate step must
148205
+ ** be the same. */
148206
+ assert( pWin==pMWin || sqlite3WindowCompare(pParse,pWin,pMWin,0)==0 );
148207
+
148208
+ for(i=0; i<nArg; i++){
148209
+ if( i!=1 || pFunc->zName!=nth_valueName ){
148210
+ sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+i, reg+i);
148211
+ }else{
148212
+ sqlite3VdbeAddOp3(v, OP_Column, pMWin->iEphCsr, pWin->iArgCol+i, reg+i);
148213
+ }
148214
+ }
148215
+ regArg = reg;
148216
+
148217
+ if( pMWin->regStartRowid==0
148218
+ && (pFunc->funcFlags & SQLITE_FUNC_MINMAX)
148219
+ && (pWin->eStart!=TK_UNBOUNDED)
148220
+ ){
148221
+ int addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, regArg);
148222
+ VdbeCoverage(v);
148223
+ if( bInverse==0 ){
148224
+ sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1, 1);
148225
+ sqlite3VdbeAddOp2(v, OP_SCopy, regArg, pWin->regApp);
148226
+ sqlite3VdbeAddOp3(v, OP_MakeRecord, pWin->regApp, 2, pWin->regApp+2);
148227
+ sqlite3VdbeAddOp2(v, OP_IdxInsert, pWin->csrApp, pWin->regApp+2);
148228
+ }else{
148229
+ sqlite3VdbeAddOp4Int(v, OP_SeekGE, pWin->csrApp, 0, regArg, 1);
148230
+ VdbeCoverageNeverTaken(v);
148231
+ sqlite3VdbeAddOp1(v, OP_Delete, pWin->csrApp);
148232
+ sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
148233
+ }
148234
+ sqlite3VdbeJumpHere(v, addrIsNull);
148235
+ }else if( pWin->regApp ){
148236
+ assert( pFunc->zName==nth_valueName
148237
+ || pFunc->zName==first_valueName
148238
+ );
148239
+ assert( bInverse==0 || bInverse==1 );
148240
+ sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1-bInverse, 1);
148241
+ }else if( pFunc->xSFunc!=noopStepFunc ){
148242
+ int addrIf = 0;
148243
+ if( pWin->pFilter ){
148244
+ int regTmp;
148245
+ assert( pWin->bExprArgs || !nArg ||nArg==pWin->pOwner->x.pList->nExpr );
148246
+ assert( pWin->bExprArgs || nArg ||pWin->pOwner->x.pList==0 );
148247
+ regTmp = sqlite3GetTempReg(pParse);
148248
+ sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+nArg,regTmp);
148249
+ addrIf = sqlite3VdbeAddOp3(v, OP_IfNot, regTmp, 0, 1);
148250
+ VdbeCoverage(v);
148251
+ sqlite3ReleaseTempReg(pParse, regTmp);
148252
+ }
148253
+
148254
+ if( pWin->bExprArgs ){
148255
+ int iStart = sqlite3VdbeCurrentAddr(v);
148256
+ VdbeOp *pOp, *pEnd;
148257
+
148258
+ nArg = pWin->pOwner->x.pList->nExpr;
148259
+ regArg = sqlite3GetTempRange(pParse, nArg);
148260
+ sqlite3ExprCodeExprList(pParse, pWin->pOwner->x.pList, regArg, 0, 0);
148261
+
148262
+ pEnd = sqlite3VdbeGetOp(v, -1);
148263
+ for(pOp=sqlite3VdbeGetOp(v, iStart); pOp<=pEnd; pOp++){
148264
+ if( pOp->opcode==OP_Column && pOp->p1==pWin->iEphCsr ){
148265
+ pOp->p1 = csr;
148266
+ }
148267
+ }
148268
+ }
148269
+ if( pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
148270
+ CollSeq *pColl;
148271
+ assert( nArg>0 );
148272
+ pColl = sqlite3ExprNNCollSeq(pParse, pWin->pOwner->x.pList->a[0].pExpr);
148273
+ sqlite3VdbeAddOp4(v, OP_CollSeq, 0,0,0, (const char*)pColl, P4_COLLSEQ);
148274
+ }
148275
+ sqlite3VdbeAddOp3(v, bInverse? OP_AggInverse : OP_AggStep,
148276
+ bInverse, regArg, pWin->regAccum);
148277
+ sqlite3VdbeAppendP4(v, pFunc, P4_FUNCDEF);
148278
+ sqlite3VdbeChangeP5(v, (u8)nArg);
148279
+ if( pWin->bExprArgs ){
148280
+ sqlite3ReleaseTempRange(pParse, regArg, nArg);
148281
+ }
148282
+ if( addrIf ) sqlite3VdbeJumpHere(v, addrIf);
148283
+ }
148284
+ }
148285
+}
148286
+
148287
+/*
148288
+** Values that may be passed as the second argument to windowCodeOp().
148289
+*/
148290
+#define WINDOW_RETURN_ROW 1
148291
+#define WINDOW_AGGINVERSE 2
148292
+#define WINDOW_AGGSTEP 3
148293
+
148272148294
/*
148273148295
** Generate VM code to invoke either xValue() (bFin==0) or xFinalize()
148274148296
** (bFin==1) for each window function in the linked list starting at
148275148297
** pMWin. Or, for built-in window-functions that do not use the standard
148276148298
** API, generate the equivalent VM code.
@@ -148329,10 +148351,12 @@
148329148351
int lblNext;
148330148352
int lblBrk;
148331148353
int addrNext;
148332148354
int csr;
148333148355
148356
+ VdbeModuleComment((v, "windowFullScan begin"));
148357
+
148334148358
assert( pMWin!=0 );
148335148359
csr = pMWin->csrApp;
148336148360
nPeer = (pMWin->pOrderBy ? pMWin->pOrderBy->nExpr : 0);
148337148361
148338148362
lblNext = sqlite3VdbeMakeLabel(pParse);
@@ -148385,11 +148409,11 @@
148385148409
sqlite3VdbeAddOp2(v, OP_Goto, 0, lblNext);
148386148410
}
148387148411
if( addrEq ) sqlite3VdbeJumpHere(v, addrEq);
148388148412
}
148389148413
148390
- windowAggStep(pParse, pMWin, csr, 0, p->regArg);
148414
+ windowAggStep(p, pMWin, csr, 0, p->regArg);
148391148415
148392148416
sqlite3VdbeResolveLabel(v, lblNext);
148393148417
sqlite3VdbeAddOp2(v, OP_Next, csr, addrNext);
148394148418
VdbeCoverage(v);
148395148419
sqlite3VdbeJumpHere(v, addrNext-1);
@@ -148400,10 +148424,11 @@
148400148424
sqlite3ReleaseTempRange(pParse, regPeer, nPeer);
148401148425
sqlite3ReleaseTempRange(pParse, regCPeer, nPeer);
148402148426
}
148403148427
148404148428
windowAggFinal(p, 1);
148429
+ VdbeModuleComment((v, "windowFullScan end"));
148405148430
}
148406148431
148407148432
/*
148408148433
** Invoke the sub-routine at regGosub (generated by code in select.c) to
148409148434
** return the current row of Window.iEphCsr. If all window functions are
@@ -148730,13 +148755,11 @@
148730148755
int csr, reg;
148731148756
Parse *pParse = p->pParse;
148732148757
Window *pMWin = p->pMWin;
148733148758
int ret = 0;
148734148759
Vdbe *v = p->pVdbe;
148735
- int addrIf = 0;
148736148760
int addrContinue = 0;
148737
- int addrGoto = 0;
148738148761
int bPeer = (pMWin->eFrmType!=TK_ROWS);
148739148762
148740148763
int lblDone = sqlite3VdbeMakeLabel(pParse);
148741148764
int addrNextRange = 0;
148742148765
@@ -148765,19 +148788,38 @@
148765148788
windowCodeRangeTest(
148766148789
p, OP_Gt, p->end.csr, regCountdown, p->current.csr, lblDone
148767148790
);
148768148791
}
148769148792
}else{
148770
- addrIf = sqlite3VdbeAddOp3(v, OP_IfPos, regCountdown, 0, 1);
148793
+ sqlite3VdbeAddOp3(v, OP_IfPos, regCountdown, lblDone, 1);
148771148794
VdbeCoverage(v);
148772148795
}
148773148796
}
148774148797
148775148798
if( op==WINDOW_RETURN_ROW && pMWin->regStartRowid==0 ){
148776148799
windowAggFinal(p, 0);
148777148800
}
148778148801
addrContinue = sqlite3VdbeCurrentAddr(v);
148802
+
148803
+ /* If this is a (RANGE BETWEEN a FOLLOWING AND b FOLLOWING) or
148804
+ ** (RANGE BETWEEN b PRECEDING AND a PRECEDING) frame, ensure the
148805
+ ** start cursor does not advance past the end cursor within the
148806
+ ** temporary table. It otherwise might, if (a>b). */
148807
+ if( pMWin->eStart==pMWin->eEnd && regCountdown
148808
+ && pMWin->eFrmType==TK_RANGE && op==WINDOW_AGGINVERSE
148809
+ ){
148810
+ int regRowid1 = sqlite3GetTempReg(pParse);
148811
+ int regRowid2 = sqlite3GetTempReg(pParse);
148812
+ sqlite3VdbeAddOp2(v, OP_Rowid, p->start.csr, regRowid1);
148813
+ sqlite3VdbeAddOp2(v, OP_Rowid, p->end.csr, regRowid2);
148814
+ sqlite3VdbeAddOp3(v, OP_Ge, regRowid2, lblDone, regRowid1);
148815
+ VdbeCoverage(v);
148816
+ sqlite3ReleaseTempReg(pParse, regRowid1);
148817
+ sqlite3ReleaseTempReg(pParse, regRowid2);
148818
+ assert( pMWin->eStart==TK_PRECEDING || pMWin->eStart==TK_FOLLOWING );
148819
+ }
148820
+
148779148821
switch( op ){
148780148822
case WINDOW_RETURN_ROW:
148781148823
csr = p->current.csr;
148782148824
reg = p->current.reg;
148783148825
windowReturnOneRow(p);
@@ -148788,11 +148830,11 @@
148788148830
reg = p->start.reg;
148789148831
if( pMWin->regStartRowid ){
148790148832
assert( pMWin->regEndRowid );
148791148833
sqlite3VdbeAddOp2(v, OP_AddImm, pMWin->regStartRowid, 1);
148792148834
}else{
148793
- windowAggStep(pParse, pMWin, csr, 1, p->regArg);
148835
+ windowAggStep(p, pMWin, csr, 1, p->regArg);
148794148836
}
148795148837
break;
148796148838
148797148839
default:
148798148840
assert( op==WINDOW_AGGSTEP );
@@ -148800,11 +148842,11 @@
148800148842
reg = p->end.reg;
148801148843
if( pMWin->regStartRowid ){
148802148844
assert( pMWin->regEndRowid );
148803148845
sqlite3VdbeAddOp2(v, OP_AddImm, pMWin->regEndRowid, 1);
148804148846
}else{
148805
- windowAggStep(pParse, pMWin, csr, 0, p->regArg);
148847
+ windowAggStep(p, pMWin, csr, 0, p->regArg);
148806148848
}
148807148849
break;
148808148850
}
148809148851
148810148852
if( op==p->eDelete ){
@@ -148818,11 +148860,11 @@
148818148860
ret = sqlite3VdbeAddOp0(v, OP_Goto);
148819148861
}else{
148820148862
sqlite3VdbeAddOp2(v, OP_Next, csr, sqlite3VdbeCurrentAddr(v)+1+bPeer);
148821148863
VdbeCoverage(v);
148822148864
if( bPeer ){
148823
- addrGoto = sqlite3VdbeAddOp0(v, OP_Goto);
148865
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, lblDone);
148824148866
}
148825148867
}
148826148868
148827148869
if( bPeer ){
148828148870
int nReg = (pMWin->pOrderBy ? pMWin->pOrderBy->nExpr : 0);
@@ -148834,12 +148876,10 @@
148834148876
148835148877
if( addrNextRange ){
148836148878
sqlite3VdbeAddOp2(v, OP_Goto, 0, addrNextRange);
148837148879
}
148838148880
sqlite3VdbeResolveLabel(v, lblDone);
148839
- if( addrGoto ) sqlite3VdbeJumpHere(v, addrGoto);
148840
- if( addrIf ) sqlite3VdbeJumpHere(v, addrIf);
148841148881
return ret;
148842148882
}
148843148883
148844148884
148845148885
/*
@@ -149188,11 +149228,11 @@
149188149228
** if( first row of partition ){
149189149229
** Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
149190149230
** regEnd = <expr2>
149191149231
** regStart = <expr1>
149192149232
** }else{
149193
-** if( (csrEnd.key + regEnd) <= csrCurrent.key ){
149233
+** while( (csrEnd.key + regEnd) <= csrCurrent.key ){
149194149234
** AGGSTEP
149195149235
** }
149196149236
** while( (csrStart.key + regStart) < csrCurrent.key ){
149197149237
** AGGINVERSE
149198149238
** }
@@ -149261,20 +149301,20 @@
149261149301
int iInput; /* To iterate through sub cols */
149262149302
int addrNe; /* Address of OP_Ne */
149263149303
int addrGosubFlush = 0; /* Address of OP_Gosub to flush: */
149264149304
int addrInteger = 0; /* Address of OP_Integer */
149265149305
int addrEmpty; /* Address of OP_Rewind in flush: */
149266
- int regStart = 0; /* Value of <expr> PRECEDING */
149267
- int regEnd = 0; /* Value of <expr> FOLLOWING */
149268149306
int regNew; /* Array of registers holding new input row */
149269149307
int regRecord; /* regNew array in record form */
149270149308
int regRowid; /* Rowid for regRecord in eph table */
149271149309
int regNewPeer = 0; /* Peer values for new row (part of regNew) */
149272149310
int regPeer = 0; /* Peer values for current row */
149273149311
int regFlushPart = 0; /* Register for "Gosub flush_partition" */
149274149312
WindowCodeArg s; /* Context object for sub-routines */
149275149313
int lblWhereEnd; /* Label just before sqlite3WhereEnd() code */
149314
+ int regStart = 0; /* Value of <expr> PRECEDING */
149315
+ int regEnd = 0; /* Value of <expr> FOLLOWING */
149276149316
149277149317
assert( pMWin->eStart==TK_PRECEDING || pMWin->eStart==TK_CURRENT
149278149318
|| pMWin->eStart==TK_FOLLOWING || pMWin->eStart==TK_UNBOUNDED
149279149319
);
149280149320
assert( pMWin->eEnd==TK_FOLLOWING || pMWin->eEnd==TK_CURRENT
@@ -149401,15 +149441,15 @@
149401149441
/* This block is run for the first row of each partition */
149402149442
s.regArg = windowInitAccum(pParse, pMWin);
149403149443
149404149444
if( regStart ){
149405149445
sqlite3ExprCode(pParse, pMWin->pStart, regStart);
149406
- windowCheckValue(pParse, regStart, 0 + (pMWin->eFrmType==TK_RANGE ? 3 : 0));
149446
+ windowCheckValue(pParse, regStart, 0 + (pMWin->eFrmType==TK_RANGE?3:0));
149407149447
}
149408149448
if( regEnd ){
149409149449
sqlite3ExprCode(pParse, pMWin->pEnd, regEnd);
149410
- windowCheckValue(pParse, regEnd, 1 + (pMWin->eFrmType==TK_RANGE ? 3 : 0));
149450
+ windowCheckValue(pParse, regEnd, 1 + (pMWin->eFrmType==TK_RANGE?3:0));
149411149451
}
149412149452
149413149453
if( pMWin->eFrmType!=TK_RANGE && pMWin->eStart==pMWin->eEnd && regStart ){
149414149454
int op = ((pMWin->eStart==TK_FOLLOWING) ? OP_Ge : OP_Le);
149415149455
int addrGe = sqlite3VdbeAddOp3(v, op, regStart, 0, regEnd);
@@ -153724,11 +153764,11 @@
153724153764
**
153725153765
** simplify to constants 0 (false) and 1 (true), respectively,
153726153766
** regardless of the value of expr1.
153727153767
*/
153728153768
sqlite3ExprUnmapAndDelete(pParse, yymsp[-4].minor.yy46);
153729
- yymsp[-4].minor.yy46 = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[yymsp[-3].minor.yy32],1);
153769
+ yymsp[-4].minor.yy46 = sqlite3Expr(pParse->db, TK_INTEGER, yymsp[-3].minor.yy32 ? "1" : "0");
153730153770
}else{
153731153771
yymsp[-4].minor.yy46 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy46, 0);
153732153772
if( yymsp[-4].minor.yy46 ){
153733153773
yymsp[-4].minor.yy46->x.pList = yymsp[-1].minor.yy138;
153734153774
sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy46);
@@ -220196,11 +220236,11 @@
220196220236
int nArg, /* Number of args */
220197220237
sqlite3_value **apUnused /* Function arguments */
220198220238
){
220199220239
assert( nArg==0 );
220200220240
UNUSED_PARAM2(nArg, apUnused);
220201
- sqlite3_result_text(pCtx, "fts5: 2019-09-21 17:31:03 8ea1dc727d391b15d0c4fa858ff68d5b8a63dde46408f24027dac8d28f044cbd", -1, SQLITE_TRANSIENT);
220241
+ sqlite3_result_text(pCtx, "fts5: 2019-09-25 18:44:49 36d35dbd5a80dc4a149ed7409cc4b43712622fc4c6a8915b4fbb62fd1d6b7763", -1, SQLITE_TRANSIENT);
220202220242
}
220203220243
220204220244
/*
220205220245
** Return true if zName is the extension on one of the shadow tables used
220206220246
** by this module.
@@ -224964,12 +225004,12 @@
224964225004
}
224965225005
#endif /* SQLITE_CORE */
224966225006
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
224967225007
224968225008
/************** End of stmt.c ************************************************/
224969
-#if __LINE__!=224969
225009
+#if __LINE__!=225009
224970225010
#undef SQLITE_SOURCE_ID
224971
-#define SQLITE_SOURCE_ID "2019-09-21 17:31:03 8ea1dc727d391b15d0c4fa858ff68d5b8a63dde46408f24027dac8d28f04alt2"
225011
+#define SQLITE_SOURCE_ID "2019-09-26 16:57:42 49073b7003330027303c4c776e9f85112f8b99b89f848fec3f953eba501dalt2"
224972225012
#endif
224973225013
/* Return the source-id for this library */
224974225014
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
224975225015
/************************** End of sqlite3.c ******************************/
224976225016
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1165,11 +1165,11 @@
1165 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1166 ** [sqlite_version()] and [sqlite_source_id()].
1167 */
1168 #define SQLITE_VERSION "3.30.0"
1169 #define SQLITE_VERSION_NUMBER 3030000
1170 #define SQLITE_SOURCE_ID "2019-09-21 17:31:03 8ea1dc727d391b15d0c4fa858ff68d5b8a63dde46408f24027dac8d28f044cbd"
1171
1172 /*
1173 ** CAPI3REF: Run-Time Library Version Numbers
1174 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1175 **
@@ -19349,11 +19349,10 @@
19349 #ifndef SQLITE_AMALGAMATION
19350 SQLITE_PRIVATE const unsigned char sqlite3OpcodeProperty[];
19351 SQLITE_PRIVATE const char sqlite3StrBINARY[];
19352 SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[];
19353 SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[];
19354 SQLITE_PRIVATE const Token sqlite3IntTokens[];
19355 SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config;
19356 SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions;
19357 #ifndef SQLITE_OMIT_WSD
19358 SQLITE_PRIVATE int sqlite3PendingByte;
19359 #endif
@@ -20020,18 +20019,10 @@
20020 ** database connections. After initialization, this table is
20021 ** read-only.
20022 */
20023 SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions;
20024
20025 /*
20026 ** Constant tokens for values 0 and 1.
20027 */
20028 SQLITE_PRIVATE const Token sqlite3IntTokens[] = {
20029 { "0", 1 },
20030 { "1", 1 }
20031 };
20032
20033 #ifdef VDBE_PROFILE
20034 /*
20035 ** The following performance counter can be used in place of
20036 ** sqlite3Hwtime() for profiling. This is a no-op on standard builds.
20037 */
@@ -38509,11 +38500,11 @@
38509 ** as the associated database file.
38510 **
38511 ** If the SQLITE_ENABLE_8_3_NAMES option is enabled, then the
38512 ** original filename is unavailable. But 8_3_NAMES is only used for
38513 ** FAT filesystems and permissions do not matter there, so just use
38514 ** the default permissions.
38515 */
38516 static int findCreateFileMode(
38517 const char *zPath, /* Path of file (possibly) being created */
38518 int flags, /* Flags passed as 4th argument to xOpen() */
38519 mode_t *pMode, /* OUT: Permissions to open file with */
@@ -38744,15 +38735,23 @@
38744 int rc2 = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zName);
38745 if( rc==SQLITE_OK ) rc = rc2;
38746 goto open_finished;
38747 }
38748
38749 /* If this process is running as root and if creating a new rollback
38750 ** journal or WAL file, set the ownership of the journal or WAL to be
38751 ** the same as the original database.
 
 
 
 
 
 
 
 
38752 */
38753 if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){
38754 robustFchown(fd, uid, gid);
38755 }
38756 }
38757 assert( fd>=0 );
38758 if( pOutFlags ){
@@ -95757,10 +95756,17 @@
95757 memcpy(pExpr, pDup, sizeof(*pExpr));
95758 if( !ExprHasProperty(pExpr, EP_IntValue) && pExpr->u.zToken!=0 ){
95759 assert( (pExpr->flags & (EP_Reduced|EP_TokenOnly))==0 );
95760 pExpr->u.zToken = sqlite3DbStrDup(db, pExpr->u.zToken);
95761 pExpr->flags |= EP_MemToken;
 
 
 
 
 
 
 
95762 }
95763 sqlite3DbFree(db, pDup);
95764 }
95765 ExprSetProperty(pExpr, EP_Alias);
95766 }
@@ -98388,11 +98394,11 @@
98388 }else if( pRight==0 ){
98389 return pLeft;
98390 }else if( ExprAlwaysFalse(pLeft) || ExprAlwaysFalse(pRight) ){
98391 sqlite3ExprUnmapAndDelete(pParse, pLeft);
98392 sqlite3ExprUnmapAndDelete(pParse, pRight);
98393 return sqlite3ExprAlloc(db, TK_INTEGER, &sqlite3IntTokens[0], 0);
98394 }else{
98395 return sqlite3PExpr(pParse, TK_AND, pLeft, pRight);
98396 }
98397 }
98398
@@ -100442,15 +100448,25 @@
100442 }else{
100443 dest.eDest = SRT_Exists;
100444 sqlite3VdbeAddOp2(v, OP_Integer, 0, dest.iSDParm);
100445 VdbeComment((v, "Init EXISTS result"));
100446 }
100447 pLimit = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[1], 0);
100448 if( pSel->pLimit ){
100449 sqlite3ExprDelete(pParse->db, pSel->pLimit->pLeft);
 
 
 
 
 
 
 
 
 
100450 pSel->pLimit->pLeft = pLimit;
100451 }else{
 
 
100452 pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0);
100453 }
100454 pSel->iLimit = 0;
100455 if( sqlite3Select(pParse, pSel, &dest) ){
100456 return 0;
@@ -131029,11 +131045,11 @@
131029 static int havingToWhereExprCb(Walker *pWalker, Expr *pExpr){
131030 if( pExpr->op!=TK_AND ){
131031 Select *pS = pWalker->u.pSelect;
131032 if( sqlite3ExprIsConstantOrGroupBy(pWalker->pParse, pExpr, pS->pGroupBy) ){
131033 sqlite3 *db = pWalker->pParse->db;
131034 Expr *pNew = sqlite3ExprAlloc(db, TK_INTEGER, &sqlite3IntTokens[1], 0);
131035 if( pNew ){
131036 Expr *pWhere = pS->pWhere;
131037 SWAP(Expr, *pNew, *pExpr);
131038 pNew = sqlite3ExprAnd(pWalker->pParse, pWhere, pNew);
131039 pS->pWhere = pNew;
@@ -147627,11 +147643,11 @@
147627 ** that pSublist is still NULL here. Add a constant expression here to
147628 ** keep everything legal in this case.
147629 */
147630 if( pSublist==0 ){
147631 pSublist = sqlite3ExprListAppend(pParse, 0,
147632 sqlite3ExprAlloc(db, TK_INTEGER, &sqlite3IntTokens[0], 0)
147633 );
147634 }
147635
147636 pSub = sqlite3SelectNew(
147637 pParse, pSublist, pSrc, pWhere, pGroupBy, pHaving, pSort, 0, 0
@@ -148044,124 +148060,10 @@
148044 static int windowArgCount(Window *pWin){
148045 ExprList *pList = pWin->pOwner->x.pList;
148046 return (pList ? pList->nExpr : 0);
148047 }
148048
148049 /*
148050 ** Generate VM code to invoke either xStep() (if bInverse is 0) or
148051 ** xInverse (if bInverse is non-zero) for each window function in the
148052 ** linked list starting at pMWin. Or, for built-in window functions
148053 ** that do not use the standard function API, generate the required
148054 ** inline VM code.
148055 **
148056 ** If argument csr is greater than or equal to 0, then argument reg is
148057 ** the first register in an array of registers guaranteed to be large
148058 ** enough to hold the array of arguments for each function. In this case
148059 ** the arguments are extracted from the current row of csr into the
148060 ** array of registers before invoking OP_AggStep or OP_AggInverse
148061 **
148062 ** Or, if csr is less than zero, then the array of registers at reg is
148063 ** already populated with all columns from the current row of the sub-query.
148064 **
148065 ** If argument regPartSize is non-zero, then it is a register containing the
148066 ** number of rows in the current partition.
148067 */
148068 static void windowAggStep(
148069 Parse *pParse,
148070 Window *pMWin, /* Linked list of window functions */
148071 int csr, /* Read arguments from this cursor */
148072 int bInverse, /* True to invoke xInverse instead of xStep */
148073 int reg /* Array of registers */
148074 ){
148075 Vdbe *v = sqlite3GetVdbe(pParse);
148076 Window *pWin;
148077 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
148078 FuncDef *pFunc = pWin->pFunc;
148079 int regArg;
148080 int nArg = pWin->bExprArgs ? 0 : windowArgCount(pWin);
148081 int i;
148082
148083 assert( bInverse==0 || pWin->eStart!=TK_UNBOUNDED );
148084
148085 for(i=0; i<nArg; i++){
148086 if( i!=1 || pFunc->zName!=nth_valueName ){
148087 sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+i, reg+i);
148088 }else{
148089 sqlite3VdbeAddOp3(v, OP_Column, pMWin->iEphCsr, pWin->iArgCol+i, reg+i);
148090 }
148091 }
148092 regArg = reg;
148093
148094 if( pMWin->regStartRowid==0
148095 && (pFunc->funcFlags & SQLITE_FUNC_MINMAX)
148096 && (pWin->eStart!=TK_UNBOUNDED)
148097 ){
148098 int addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, regArg);
148099 VdbeCoverage(v);
148100 if( bInverse==0 ){
148101 sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1, 1);
148102 sqlite3VdbeAddOp2(v, OP_SCopy, regArg, pWin->regApp);
148103 sqlite3VdbeAddOp3(v, OP_MakeRecord, pWin->regApp, 2, pWin->regApp+2);
148104 sqlite3VdbeAddOp2(v, OP_IdxInsert, pWin->csrApp, pWin->regApp+2);
148105 }else{
148106 sqlite3VdbeAddOp4Int(v, OP_SeekGE, pWin->csrApp, 0, regArg, 1);
148107 VdbeCoverageNeverTaken(v);
148108 sqlite3VdbeAddOp1(v, OP_Delete, pWin->csrApp);
148109 sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
148110 }
148111 sqlite3VdbeJumpHere(v, addrIsNull);
148112 }else if( pWin->regApp ){
148113 assert( pFunc->zName==nth_valueName
148114 || pFunc->zName==first_valueName
148115 );
148116 assert( bInverse==0 || bInverse==1 );
148117 sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1-bInverse, 1);
148118 }else if( pFunc->xSFunc!=noopStepFunc ){
148119 int addrIf = 0;
148120 if( pWin->pFilter ){
148121 int regTmp;
148122 assert( pWin->bExprArgs || !nArg ||nArg==pWin->pOwner->x.pList->nExpr );
148123 assert( pWin->bExprArgs || nArg ||pWin->pOwner->x.pList==0 );
148124 regTmp = sqlite3GetTempReg(pParse);
148125 sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+nArg,regTmp);
148126 addrIf = sqlite3VdbeAddOp3(v, OP_IfNot, regTmp, 0, 1);
148127 VdbeCoverage(v);
148128 sqlite3ReleaseTempReg(pParse, regTmp);
148129 }
148130 if( pWin->bExprArgs ){
148131 int iStart = sqlite3VdbeCurrentAddr(v);
148132 VdbeOp *pOp, *pEnd;
148133
148134 nArg = pWin->pOwner->x.pList->nExpr;
148135 regArg = sqlite3GetTempRange(pParse, nArg);
148136 sqlite3ExprCodeExprList(pParse, pWin->pOwner->x.pList, regArg, 0, 0);
148137
148138 pEnd = sqlite3VdbeGetOp(v, -1);
148139 for(pOp=sqlite3VdbeGetOp(v, iStart); pOp<=pEnd; pOp++){
148140 if( pOp->opcode==OP_Column && pOp->p1==pWin->iEphCsr ){
148141 pOp->p1 = csr;
148142 }
148143 }
148144 }
148145 if( pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
148146 CollSeq *pColl;
148147 assert( nArg>0 );
148148 pColl = sqlite3ExprNNCollSeq(pParse, pWin->pOwner->x.pList->a[0].pExpr);
148149 sqlite3VdbeAddOp4(v, OP_CollSeq, 0,0,0, (const char*)pColl, P4_COLLSEQ);
148150 }
148151 sqlite3VdbeAddOp3(v, bInverse? OP_AggInverse : OP_AggStep,
148152 bInverse, regArg, pWin->regAccum);
148153 sqlite3VdbeAppendP4(v, pFunc, P4_FUNCDEF);
148154 sqlite3VdbeChangeP5(v, (u8)nArg);
148155 if( pWin->bExprArgs ){
148156 sqlite3ReleaseTempRange(pParse, regArg, nArg);
148157 }
148158 if( addrIf ) sqlite3VdbeJumpHere(v, addrIf);
148159 }
148160 }
148161 }
148162
148163 typedef struct WindowCodeArg WindowCodeArg;
148164 typedef struct WindowCsrAndReg WindowCsrAndReg;
148165
148166 /*
148167 ** See comments above struct WindowCodeArg.
@@ -148238,17 +148140,10 @@
148238 WindowCsrAndReg start;
148239 WindowCsrAndReg current;
148240 WindowCsrAndReg end;
148241 };
148242
148243 /*
148244 ** Values that may be passed as the second argument to windowCodeOp().
148245 */
148246 #define WINDOW_RETURN_ROW 1
148247 #define WINDOW_AGGINVERSE 2
148248 #define WINDOW_AGGSTEP 3
148249
148250 /*
148251 ** Generate VM code to read the window frames peer values from cursor csr into
148252 ** an array of registers starting at reg.
148253 */
148254 static void windowReadPeerValues(
@@ -148267,10 +148162,137 @@
148267 sqlite3VdbeAddOp3(v, OP_Column, csr, iColOff+i, reg+i);
148268 }
148269 }
148270 }
148271
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148272 /*
148273 ** Generate VM code to invoke either xValue() (bFin==0) or xFinalize()
148274 ** (bFin==1) for each window function in the linked list starting at
148275 ** pMWin. Or, for built-in window-functions that do not use the standard
148276 ** API, generate the equivalent VM code.
@@ -148329,10 +148351,12 @@
148329 int lblNext;
148330 int lblBrk;
148331 int addrNext;
148332 int csr;
148333
 
 
148334 assert( pMWin!=0 );
148335 csr = pMWin->csrApp;
148336 nPeer = (pMWin->pOrderBy ? pMWin->pOrderBy->nExpr : 0);
148337
148338 lblNext = sqlite3VdbeMakeLabel(pParse);
@@ -148385,11 +148409,11 @@
148385 sqlite3VdbeAddOp2(v, OP_Goto, 0, lblNext);
148386 }
148387 if( addrEq ) sqlite3VdbeJumpHere(v, addrEq);
148388 }
148389
148390 windowAggStep(pParse, pMWin, csr, 0, p->regArg);
148391
148392 sqlite3VdbeResolveLabel(v, lblNext);
148393 sqlite3VdbeAddOp2(v, OP_Next, csr, addrNext);
148394 VdbeCoverage(v);
148395 sqlite3VdbeJumpHere(v, addrNext-1);
@@ -148400,10 +148424,11 @@
148400 sqlite3ReleaseTempRange(pParse, regPeer, nPeer);
148401 sqlite3ReleaseTempRange(pParse, regCPeer, nPeer);
148402 }
148403
148404 windowAggFinal(p, 1);
 
148405 }
148406
148407 /*
148408 ** Invoke the sub-routine at regGosub (generated by code in select.c) to
148409 ** return the current row of Window.iEphCsr. If all window functions are
@@ -148730,13 +148755,11 @@
148730 int csr, reg;
148731 Parse *pParse = p->pParse;
148732 Window *pMWin = p->pMWin;
148733 int ret = 0;
148734 Vdbe *v = p->pVdbe;
148735 int addrIf = 0;
148736 int addrContinue = 0;
148737 int addrGoto = 0;
148738 int bPeer = (pMWin->eFrmType!=TK_ROWS);
148739
148740 int lblDone = sqlite3VdbeMakeLabel(pParse);
148741 int addrNextRange = 0;
148742
@@ -148765,19 +148788,38 @@
148765 windowCodeRangeTest(
148766 p, OP_Gt, p->end.csr, regCountdown, p->current.csr, lblDone
148767 );
148768 }
148769 }else{
148770 addrIf = sqlite3VdbeAddOp3(v, OP_IfPos, regCountdown, 0, 1);
148771 VdbeCoverage(v);
148772 }
148773 }
148774
148775 if( op==WINDOW_RETURN_ROW && pMWin->regStartRowid==0 ){
148776 windowAggFinal(p, 0);
148777 }
148778 addrContinue = sqlite3VdbeCurrentAddr(v);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148779 switch( op ){
148780 case WINDOW_RETURN_ROW:
148781 csr = p->current.csr;
148782 reg = p->current.reg;
148783 windowReturnOneRow(p);
@@ -148788,11 +148830,11 @@
148788 reg = p->start.reg;
148789 if( pMWin->regStartRowid ){
148790 assert( pMWin->regEndRowid );
148791 sqlite3VdbeAddOp2(v, OP_AddImm, pMWin->regStartRowid, 1);
148792 }else{
148793 windowAggStep(pParse, pMWin, csr, 1, p->regArg);
148794 }
148795 break;
148796
148797 default:
148798 assert( op==WINDOW_AGGSTEP );
@@ -148800,11 +148842,11 @@
148800 reg = p->end.reg;
148801 if( pMWin->regStartRowid ){
148802 assert( pMWin->regEndRowid );
148803 sqlite3VdbeAddOp2(v, OP_AddImm, pMWin->regEndRowid, 1);
148804 }else{
148805 windowAggStep(pParse, pMWin, csr, 0, p->regArg);
148806 }
148807 break;
148808 }
148809
148810 if( op==p->eDelete ){
@@ -148818,11 +148860,11 @@
148818 ret = sqlite3VdbeAddOp0(v, OP_Goto);
148819 }else{
148820 sqlite3VdbeAddOp2(v, OP_Next, csr, sqlite3VdbeCurrentAddr(v)+1+bPeer);
148821 VdbeCoverage(v);
148822 if( bPeer ){
148823 addrGoto = sqlite3VdbeAddOp0(v, OP_Goto);
148824 }
148825 }
148826
148827 if( bPeer ){
148828 int nReg = (pMWin->pOrderBy ? pMWin->pOrderBy->nExpr : 0);
@@ -148834,12 +148876,10 @@
148834
148835 if( addrNextRange ){
148836 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrNextRange);
148837 }
148838 sqlite3VdbeResolveLabel(v, lblDone);
148839 if( addrGoto ) sqlite3VdbeJumpHere(v, addrGoto);
148840 if( addrIf ) sqlite3VdbeJumpHere(v, addrIf);
148841 return ret;
148842 }
148843
148844
148845 /*
@@ -149188,11 +149228,11 @@
149188 ** if( first row of partition ){
149189 ** Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
149190 ** regEnd = <expr2>
149191 ** regStart = <expr1>
149192 ** }else{
149193 ** if( (csrEnd.key + regEnd) <= csrCurrent.key ){
149194 ** AGGSTEP
149195 ** }
149196 ** while( (csrStart.key + regStart) < csrCurrent.key ){
149197 ** AGGINVERSE
149198 ** }
@@ -149261,20 +149301,20 @@
149261 int iInput; /* To iterate through sub cols */
149262 int addrNe; /* Address of OP_Ne */
149263 int addrGosubFlush = 0; /* Address of OP_Gosub to flush: */
149264 int addrInteger = 0; /* Address of OP_Integer */
149265 int addrEmpty; /* Address of OP_Rewind in flush: */
149266 int regStart = 0; /* Value of <expr> PRECEDING */
149267 int regEnd = 0; /* Value of <expr> FOLLOWING */
149268 int regNew; /* Array of registers holding new input row */
149269 int regRecord; /* regNew array in record form */
149270 int regRowid; /* Rowid for regRecord in eph table */
149271 int regNewPeer = 0; /* Peer values for new row (part of regNew) */
149272 int regPeer = 0; /* Peer values for current row */
149273 int regFlushPart = 0; /* Register for "Gosub flush_partition" */
149274 WindowCodeArg s; /* Context object for sub-routines */
149275 int lblWhereEnd; /* Label just before sqlite3WhereEnd() code */
 
 
149276
149277 assert( pMWin->eStart==TK_PRECEDING || pMWin->eStart==TK_CURRENT
149278 || pMWin->eStart==TK_FOLLOWING || pMWin->eStart==TK_UNBOUNDED
149279 );
149280 assert( pMWin->eEnd==TK_FOLLOWING || pMWin->eEnd==TK_CURRENT
@@ -149401,15 +149441,15 @@
149401 /* This block is run for the first row of each partition */
149402 s.regArg = windowInitAccum(pParse, pMWin);
149403
149404 if( regStart ){
149405 sqlite3ExprCode(pParse, pMWin->pStart, regStart);
149406 windowCheckValue(pParse, regStart, 0 + (pMWin->eFrmType==TK_RANGE ? 3 : 0));
149407 }
149408 if( regEnd ){
149409 sqlite3ExprCode(pParse, pMWin->pEnd, regEnd);
149410 windowCheckValue(pParse, regEnd, 1 + (pMWin->eFrmType==TK_RANGE ? 3 : 0));
149411 }
149412
149413 if( pMWin->eFrmType!=TK_RANGE && pMWin->eStart==pMWin->eEnd && regStart ){
149414 int op = ((pMWin->eStart==TK_FOLLOWING) ? OP_Ge : OP_Le);
149415 int addrGe = sqlite3VdbeAddOp3(v, op, regStart, 0, regEnd);
@@ -153724,11 +153764,11 @@
153724 **
153725 ** simplify to constants 0 (false) and 1 (true), respectively,
153726 ** regardless of the value of expr1.
153727 */
153728 sqlite3ExprUnmapAndDelete(pParse, yymsp[-4].minor.yy46);
153729 yymsp[-4].minor.yy46 = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[yymsp[-3].minor.yy32],1);
153730 }else{
153731 yymsp[-4].minor.yy46 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy46, 0);
153732 if( yymsp[-4].minor.yy46 ){
153733 yymsp[-4].minor.yy46->x.pList = yymsp[-1].minor.yy138;
153734 sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy46);
@@ -220196,11 +220236,11 @@
220196 int nArg, /* Number of args */
220197 sqlite3_value **apUnused /* Function arguments */
220198 ){
220199 assert( nArg==0 );
220200 UNUSED_PARAM2(nArg, apUnused);
220201 sqlite3_result_text(pCtx, "fts5: 2019-09-21 17:31:03 8ea1dc727d391b15d0c4fa858ff68d5b8a63dde46408f24027dac8d28f044cbd", -1, SQLITE_TRANSIENT);
220202 }
220203
220204 /*
220205 ** Return true if zName is the extension on one of the shadow tables used
220206 ** by this module.
@@ -224964,12 +225004,12 @@
224964 }
224965 #endif /* SQLITE_CORE */
224966 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
224967
224968 /************** End of stmt.c ************************************************/
224969 #if __LINE__!=224969
224970 #undef SQLITE_SOURCE_ID
224971 #define SQLITE_SOURCE_ID "2019-09-21 17:31:03 8ea1dc727d391b15d0c4fa858ff68d5b8a63dde46408f24027dac8d28f04alt2"
224972 #endif
224973 /* Return the source-id for this library */
224974 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
224975 /************************** End of sqlite3.c ******************************/
224976
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1165,11 +1165,11 @@
1165 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1166 ** [sqlite_version()] and [sqlite_source_id()].
1167 */
1168 #define SQLITE_VERSION "3.30.0"
1169 #define SQLITE_VERSION_NUMBER 3030000
1170 #define SQLITE_SOURCE_ID "2019-09-26 16:57:42 49073b7003330027303c4c776e9f85112f8b99b89f848fec3f953eba501d7505"
1171
1172 /*
1173 ** CAPI3REF: Run-Time Library Version Numbers
1174 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1175 **
@@ -19349,11 +19349,10 @@
19349 #ifndef SQLITE_AMALGAMATION
19350 SQLITE_PRIVATE const unsigned char sqlite3OpcodeProperty[];
19351 SQLITE_PRIVATE const char sqlite3StrBINARY[];
19352 SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[];
19353 SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[];
 
19354 SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config;
19355 SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions;
19356 #ifndef SQLITE_OMIT_WSD
19357 SQLITE_PRIVATE int sqlite3PendingByte;
19358 #endif
@@ -20020,18 +20019,10 @@
20019 ** database connections. After initialization, this table is
20020 ** read-only.
20021 */
20022 SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions;
20023
 
 
 
 
 
 
 
 
20024 #ifdef VDBE_PROFILE
20025 /*
20026 ** The following performance counter can be used in place of
20027 ** sqlite3Hwtime() for profiling. This is a no-op on standard builds.
20028 */
@@ -38509,11 +38500,11 @@
38500 ** as the associated database file.
38501 **
38502 ** If the SQLITE_ENABLE_8_3_NAMES option is enabled, then the
38503 ** original filename is unavailable. But 8_3_NAMES is only used for
38504 ** FAT filesystems and permissions do not matter there, so just use
38505 ** the default permissions. In 8_3_NAMES mode, leave *pMode set to zero.
38506 */
38507 static int findCreateFileMode(
38508 const char *zPath, /* Path of file (possibly) being created */
38509 int flags, /* Flags passed as 4th argument to xOpen() */
38510 mode_t *pMode, /* OUT: Permissions to open file with */
@@ -38744,15 +38735,23 @@
38735 int rc2 = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zName);
38736 if( rc==SQLITE_OK ) rc = rc2;
38737 goto open_finished;
38738 }
38739
38740 /* The owner of the rollback journal or WAL file should always be the
38741 ** same as the owner of the database file. Try to ensure that this is
38742 ** the case. The chown() system call will be a no-op if the current
38743 ** process lacks root privileges, be we should at least try. Without
38744 ** this step, if a root process opens a database file, it can leave
38745 ** behinds a journal/WAL that is owned by root and hence make the
38746 ** database inaccessible to unprivileged processes.
38747 **
38748 ** If openMode==0, then that means uid and gid are not set correctly
38749 ** (probably because SQLite is configured to use 8+3 filename mode) and
38750 ** in that case we do not want to attempt the chown().
38751 */
38752 if( openMode && (flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL))!=0 ){
38753 robustFchown(fd, uid, gid);
38754 }
38755 }
38756 assert( fd>=0 );
38757 if( pOutFlags ){
@@ -95757,10 +95756,17 @@
95756 memcpy(pExpr, pDup, sizeof(*pExpr));
95757 if( !ExprHasProperty(pExpr, EP_IntValue) && pExpr->u.zToken!=0 ){
95758 assert( (pExpr->flags & (EP_Reduced|EP_TokenOnly))==0 );
95759 pExpr->u.zToken = sqlite3DbStrDup(db, pExpr->u.zToken);
95760 pExpr->flags |= EP_MemToken;
95761 }
95762 if( ExprHasProperty(pExpr, EP_WinFunc) ){
95763 if( pExpr->y.pWin!=0 ){
95764 pExpr->y.pWin->pOwner = pExpr;
95765 }else{
95766 assert( db->mallocFailed );
95767 }
95768 }
95769 sqlite3DbFree(db, pDup);
95770 }
95771 ExprSetProperty(pExpr, EP_Alias);
95772 }
@@ -98388,11 +98394,11 @@
98394 }else if( pRight==0 ){
98395 return pLeft;
98396 }else if( ExprAlwaysFalse(pLeft) || ExprAlwaysFalse(pRight) ){
98397 sqlite3ExprUnmapAndDelete(pParse, pLeft);
98398 sqlite3ExprUnmapAndDelete(pParse, pRight);
98399 return sqlite3Expr(db, TK_INTEGER, "0");
98400 }else{
98401 return sqlite3PExpr(pParse, TK_AND, pLeft, pRight);
98402 }
98403 }
98404
@@ -100442,15 +100448,25 @@
100448 }else{
100449 dest.eDest = SRT_Exists;
100450 sqlite3VdbeAddOp2(v, OP_Integer, 0, dest.iSDParm);
100451 VdbeComment((v, "Init EXISTS result"));
100452 }
 
100453 if( pSel->pLimit ){
100454 /* The subquery already has a limit. If the pre-existing limit is X
100455 ** then make the new limit X<>0 so that the new limit is either 1 or 0 */
100456 sqlite3 *db = pParse->db;
100457 pLimit = sqlite3Expr(db, TK_INTEGER, "0");
100458 if( pLimit ){
100459 pLimit->affExpr = SQLITE_AFF_NUMERIC;
100460 pLimit = sqlite3PExpr(pParse, TK_NE,
100461 sqlite3ExprDup(db, pSel->pLimit->pLeft, 0), pLimit);
100462 }
100463 sqlite3ExprDelete(db, pSel->pLimit->pLeft);
100464 pSel->pLimit->pLeft = pLimit;
100465 }else{
100466 /* If there is no pre-existing limit add a limit of 1 */
100467 pLimit = sqlite3Expr(pParse->db, TK_INTEGER, "1");
100468 pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0);
100469 }
100470 pSel->iLimit = 0;
100471 if( sqlite3Select(pParse, pSel, &dest) ){
100472 return 0;
@@ -131029,11 +131045,11 @@
131045 static int havingToWhereExprCb(Walker *pWalker, Expr *pExpr){
131046 if( pExpr->op!=TK_AND ){
131047 Select *pS = pWalker->u.pSelect;
131048 if( sqlite3ExprIsConstantOrGroupBy(pWalker->pParse, pExpr, pS->pGroupBy) ){
131049 sqlite3 *db = pWalker->pParse->db;
131050 Expr *pNew = sqlite3Expr(db, TK_INTEGER, "1");
131051 if( pNew ){
131052 Expr *pWhere = pS->pWhere;
131053 SWAP(Expr, *pNew, *pExpr);
131054 pNew = sqlite3ExprAnd(pWalker->pParse, pWhere, pNew);
131055 pS->pWhere = pNew;
@@ -147627,11 +147643,11 @@
147643 ** that pSublist is still NULL here. Add a constant expression here to
147644 ** keep everything legal in this case.
147645 */
147646 if( pSublist==0 ){
147647 pSublist = sqlite3ExprListAppend(pParse, 0,
147648 sqlite3Expr(db, TK_INTEGER, "0")
147649 );
147650 }
147651
147652 pSub = sqlite3SelectNew(
147653 pParse, pSublist, pSrc, pWhere, pGroupBy, pHaving, pSort, 0, 0
@@ -148044,124 +148060,10 @@
148060 static int windowArgCount(Window *pWin){
148061 ExprList *pList = pWin->pOwner->x.pList;
148062 return (pList ? pList->nExpr : 0);
148063 }
148064
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148065 typedef struct WindowCodeArg WindowCodeArg;
148066 typedef struct WindowCsrAndReg WindowCsrAndReg;
148067
148068 /*
148069 ** See comments above struct WindowCodeArg.
@@ -148238,17 +148140,10 @@
148140 WindowCsrAndReg start;
148141 WindowCsrAndReg current;
148142 WindowCsrAndReg end;
148143 };
148144
 
 
 
 
 
 
 
148145 /*
148146 ** Generate VM code to read the window frames peer values from cursor csr into
148147 ** an array of registers starting at reg.
148148 */
148149 static void windowReadPeerValues(
@@ -148267,10 +148162,137 @@
148162 sqlite3VdbeAddOp3(v, OP_Column, csr, iColOff+i, reg+i);
148163 }
148164 }
148165 }
148166
148167 /*
148168 ** Generate VM code to invoke either xStep() (if bInverse is 0) or
148169 ** xInverse (if bInverse is non-zero) for each window function in the
148170 ** linked list starting at pMWin. Or, for built-in window functions
148171 ** that do not use the standard function API, generate the required
148172 ** inline VM code.
148173 **
148174 ** If argument csr is greater than or equal to 0, then argument reg is
148175 ** the first register in an array of registers guaranteed to be large
148176 ** enough to hold the array of arguments for each function. In this case
148177 ** the arguments are extracted from the current row of csr into the
148178 ** array of registers before invoking OP_AggStep or OP_AggInverse
148179 **
148180 ** Or, if csr is less than zero, then the array of registers at reg is
148181 ** already populated with all columns from the current row of the sub-query.
148182 **
148183 ** If argument regPartSize is non-zero, then it is a register containing the
148184 ** number of rows in the current partition.
148185 */
148186 static void windowAggStep(
148187 WindowCodeArg *p,
148188 Window *pMWin, /* Linked list of window functions */
148189 int csr, /* Read arguments from this cursor */
148190 int bInverse, /* True to invoke xInverse instead of xStep */
148191 int reg /* Array of registers */
148192 ){
148193 Parse *pParse = p->pParse;
148194 Vdbe *v = sqlite3GetVdbe(pParse);
148195 Window *pWin;
148196 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
148197 FuncDef *pFunc = pWin->pFunc;
148198 int regArg;
148199 int nArg = pWin->bExprArgs ? 0 : windowArgCount(pWin);
148200 int i;
148201
148202 assert( bInverse==0 || pWin->eStart!=TK_UNBOUNDED );
148203
148204 /* All OVER clauses in the same window function aggregate step must
148205 ** be the same. */
148206 assert( pWin==pMWin || sqlite3WindowCompare(pParse,pWin,pMWin,0)==0 );
148207
148208 for(i=0; i<nArg; i++){
148209 if( i!=1 || pFunc->zName!=nth_valueName ){
148210 sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+i, reg+i);
148211 }else{
148212 sqlite3VdbeAddOp3(v, OP_Column, pMWin->iEphCsr, pWin->iArgCol+i, reg+i);
148213 }
148214 }
148215 regArg = reg;
148216
148217 if( pMWin->regStartRowid==0
148218 && (pFunc->funcFlags & SQLITE_FUNC_MINMAX)
148219 && (pWin->eStart!=TK_UNBOUNDED)
148220 ){
148221 int addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, regArg);
148222 VdbeCoverage(v);
148223 if( bInverse==0 ){
148224 sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1, 1);
148225 sqlite3VdbeAddOp2(v, OP_SCopy, regArg, pWin->regApp);
148226 sqlite3VdbeAddOp3(v, OP_MakeRecord, pWin->regApp, 2, pWin->regApp+2);
148227 sqlite3VdbeAddOp2(v, OP_IdxInsert, pWin->csrApp, pWin->regApp+2);
148228 }else{
148229 sqlite3VdbeAddOp4Int(v, OP_SeekGE, pWin->csrApp, 0, regArg, 1);
148230 VdbeCoverageNeverTaken(v);
148231 sqlite3VdbeAddOp1(v, OP_Delete, pWin->csrApp);
148232 sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
148233 }
148234 sqlite3VdbeJumpHere(v, addrIsNull);
148235 }else if( pWin->regApp ){
148236 assert( pFunc->zName==nth_valueName
148237 || pFunc->zName==first_valueName
148238 );
148239 assert( bInverse==0 || bInverse==1 );
148240 sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1-bInverse, 1);
148241 }else if( pFunc->xSFunc!=noopStepFunc ){
148242 int addrIf = 0;
148243 if( pWin->pFilter ){
148244 int regTmp;
148245 assert( pWin->bExprArgs || !nArg ||nArg==pWin->pOwner->x.pList->nExpr );
148246 assert( pWin->bExprArgs || nArg ||pWin->pOwner->x.pList==0 );
148247 regTmp = sqlite3GetTempReg(pParse);
148248 sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+nArg,regTmp);
148249 addrIf = sqlite3VdbeAddOp3(v, OP_IfNot, regTmp, 0, 1);
148250 VdbeCoverage(v);
148251 sqlite3ReleaseTempReg(pParse, regTmp);
148252 }
148253
148254 if( pWin->bExprArgs ){
148255 int iStart = sqlite3VdbeCurrentAddr(v);
148256 VdbeOp *pOp, *pEnd;
148257
148258 nArg = pWin->pOwner->x.pList->nExpr;
148259 regArg = sqlite3GetTempRange(pParse, nArg);
148260 sqlite3ExprCodeExprList(pParse, pWin->pOwner->x.pList, regArg, 0, 0);
148261
148262 pEnd = sqlite3VdbeGetOp(v, -1);
148263 for(pOp=sqlite3VdbeGetOp(v, iStart); pOp<=pEnd; pOp++){
148264 if( pOp->opcode==OP_Column && pOp->p1==pWin->iEphCsr ){
148265 pOp->p1 = csr;
148266 }
148267 }
148268 }
148269 if( pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
148270 CollSeq *pColl;
148271 assert( nArg>0 );
148272 pColl = sqlite3ExprNNCollSeq(pParse, pWin->pOwner->x.pList->a[0].pExpr);
148273 sqlite3VdbeAddOp4(v, OP_CollSeq, 0,0,0, (const char*)pColl, P4_COLLSEQ);
148274 }
148275 sqlite3VdbeAddOp3(v, bInverse? OP_AggInverse : OP_AggStep,
148276 bInverse, regArg, pWin->regAccum);
148277 sqlite3VdbeAppendP4(v, pFunc, P4_FUNCDEF);
148278 sqlite3VdbeChangeP5(v, (u8)nArg);
148279 if( pWin->bExprArgs ){
148280 sqlite3ReleaseTempRange(pParse, regArg, nArg);
148281 }
148282 if( addrIf ) sqlite3VdbeJumpHere(v, addrIf);
148283 }
148284 }
148285 }
148286
148287 /*
148288 ** Values that may be passed as the second argument to windowCodeOp().
148289 */
148290 #define WINDOW_RETURN_ROW 1
148291 #define WINDOW_AGGINVERSE 2
148292 #define WINDOW_AGGSTEP 3
148293
148294 /*
148295 ** Generate VM code to invoke either xValue() (bFin==0) or xFinalize()
148296 ** (bFin==1) for each window function in the linked list starting at
148297 ** pMWin. Or, for built-in window-functions that do not use the standard
148298 ** API, generate the equivalent VM code.
@@ -148329,10 +148351,12 @@
148351 int lblNext;
148352 int lblBrk;
148353 int addrNext;
148354 int csr;
148355
148356 VdbeModuleComment((v, "windowFullScan begin"));
148357
148358 assert( pMWin!=0 );
148359 csr = pMWin->csrApp;
148360 nPeer = (pMWin->pOrderBy ? pMWin->pOrderBy->nExpr : 0);
148361
148362 lblNext = sqlite3VdbeMakeLabel(pParse);
@@ -148385,11 +148409,11 @@
148409 sqlite3VdbeAddOp2(v, OP_Goto, 0, lblNext);
148410 }
148411 if( addrEq ) sqlite3VdbeJumpHere(v, addrEq);
148412 }
148413
148414 windowAggStep(p, pMWin, csr, 0, p->regArg);
148415
148416 sqlite3VdbeResolveLabel(v, lblNext);
148417 sqlite3VdbeAddOp2(v, OP_Next, csr, addrNext);
148418 VdbeCoverage(v);
148419 sqlite3VdbeJumpHere(v, addrNext-1);
@@ -148400,10 +148424,11 @@
148424 sqlite3ReleaseTempRange(pParse, regPeer, nPeer);
148425 sqlite3ReleaseTempRange(pParse, regCPeer, nPeer);
148426 }
148427
148428 windowAggFinal(p, 1);
148429 VdbeModuleComment((v, "windowFullScan end"));
148430 }
148431
148432 /*
148433 ** Invoke the sub-routine at regGosub (generated by code in select.c) to
148434 ** return the current row of Window.iEphCsr. If all window functions are
@@ -148730,13 +148755,11 @@
148755 int csr, reg;
148756 Parse *pParse = p->pParse;
148757 Window *pMWin = p->pMWin;
148758 int ret = 0;
148759 Vdbe *v = p->pVdbe;
 
148760 int addrContinue = 0;
 
148761 int bPeer = (pMWin->eFrmType!=TK_ROWS);
148762
148763 int lblDone = sqlite3VdbeMakeLabel(pParse);
148764 int addrNextRange = 0;
148765
@@ -148765,19 +148788,38 @@
148788 windowCodeRangeTest(
148789 p, OP_Gt, p->end.csr, regCountdown, p->current.csr, lblDone
148790 );
148791 }
148792 }else{
148793 sqlite3VdbeAddOp3(v, OP_IfPos, regCountdown, lblDone, 1);
148794 VdbeCoverage(v);
148795 }
148796 }
148797
148798 if( op==WINDOW_RETURN_ROW && pMWin->regStartRowid==0 ){
148799 windowAggFinal(p, 0);
148800 }
148801 addrContinue = sqlite3VdbeCurrentAddr(v);
148802
148803 /* If this is a (RANGE BETWEEN a FOLLOWING AND b FOLLOWING) or
148804 ** (RANGE BETWEEN b PRECEDING AND a PRECEDING) frame, ensure the
148805 ** start cursor does not advance past the end cursor within the
148806 ** temporary table. It otherwise might, if (a>b). */
148807 if( pMWin->eStart==pMWin->eEnd && regCountdown
148808 && pMWin->eFrmType==TK_RANGE && op==WINDOW_AGGINVERSE
148809 ){
148810 int regRowid1 = sqlite3GetTempReg(pParse);
148811 int regRowid2 = sqlite3GetTempReg(pParse);
148812 sqlite3VdbeAddOp2(v, OP_Rowid, p->start.csr, regRowid1);
148813 sqlite3VdbeAddOp2(v, OP_Rowid, p->end.csr, regRowid2);
148814 sqlite3VdbeAddOp3(v, OP_Ge, regRowid2, lblDone, regRowid1);
148815 VdbeCoverage(v);
148816 sqlite3ReleaseTempReg(pParse, regRowid1);
148817 sqlite3ReleaseTempReg(pParse, regRowid2);
148818 assert( pMWin->eStart==TK_PRECEDING || pMWin->eStart==TK_FOLLOWING );
148819 }
148820
148821 switch( op ){
148822 case WINDOW_RETURN_ROW:
148823 csr = p->current.csr;
148824 reg = p->current.reg;
148825 windowReturnOneRow(p);
@@ -148788,11 +148830,11 @@
148830 reg = p->start.reg;
148831 if( pMWin->regStartRowid ){
148832 assert( pMWin->regEndRowid );
148833 sqlite3VdbeAddOp2(v, OP_AddImm, pMWin->regStartRowid, 1);
148834 }else{
148835 windowAggStep(p, pMWin, csr, 1, p->regArg);
148836 }
148837 break;
148838
148839 default:
148840 assert( op==WINDOW_AGGSTEP );
@@ -148800,11 +148842,11 @@
148842 reg = p->end.reg;
148843 if( pMWin->regStartRowid ){
148844 assert( pMWin->regEndRowid );
148845 sqlite3VdbeAddOp2(v, OP_AddImm, pMWin->regEndRowid, 1);
148846 }else{
148847 windowAggStep(p, pMWin, csr, 0, p->regArg);
148848 }
148849 break;
148850 }
148851
148852 if( op==p->eDelete ){
@@ -148818,11 +148860,11 @@
148860 ret = sqlite3VdbeAddOp0(v, OP_Goto);
148861 }else{
148862 sqlite3VdbeAddOp2(v, OP_Next, csr, sqlite3VdbeCurrentAddr(v)+1+bPeer);
148863 VdbeCoverage(v);
148864 if( bPeer ){
148865 sqlite3VdbeAddOp2(v, OP_Goto, 0, lblDone);
148866 }
148867 }
148868
148869 if( bPeer ){
148870 int nReg = (pMWin->pOrderBy ? pMWin->pOrderBy->nExpr : 0);
@@ -148834,12 +148876,10 @@
148876
148877 if( addrNextRange ){
148878 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrNextRange);
148879 }
148880 sqlite3VdbeResolveLabel(v, lblDone);
 
 
148881 return ret;
148882 }
148883
148884
148885 /*
@@ -149188,11 +149228,11 @@
149228 ** if( first row of partition ){
149229 ** Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
149230 ** regEnd = <expr2>
149231 ** regStart = <expr1>
149232 ** }else{
149233 ** while( (csrEnd.key + regEnd) <= csrCurrent.key ){
149234 ** AGGSTEP
149235 ** }
149236 ** while( (csrStart.key + regStart) < csrCurrent.key ){
149237 ** AGGINVERSE
149238 ** }
@@ -149261,20 +149301,20 @@
149301 int iInput; /* To iterate through sub cols */
149302 int addrNe; /* Address of OP_Ne */
149303 int addrGosubFlush = 0; /* Address of OP_Gosub to flush: */
149304 int addrInteger = 0; /* Address of OP_Integer */
149305 int addrEmpty; /* Address of OP_Rewind in flush: */
 
 
149306 int regNew; /* Array of registers holding new input row */
149307 int regRecord; /* regNew array in record form */
149308 int regRowid; /* Rowid for regRecord in eph table */
149309 int regNewPeer = 0; /* Peer values for new row (part of regNew) */
149310 int regPeer = 0; /* Peer values for current row */
149311 int regFlushPart = 0; /* Register for "Gosub flush_partition" */
149312 WindowCodeArg s; /* Context object for sub-routines */
149313 int lblWhereEnd; /* Label just before sqlite3WhereEnd() code */
149314 int regStart = 0; /* Value of <expr> PRECEDING */
149315 int regEnd = 0; /* Value of <expr> FOLLOWING */
149316
149317 assert( pMWin->eStart==TK_PRECEDING || pMWin->eStart==TK_CURRENT
149318 || pMWin->eStart==TK_FOLLOWING || pMWin->eStart==TK_UNBOUNDED
149319 );
149320 assert( pMWin->eEnd==TK_FOLLOWING || pMWin->eEnd==TK_CURRENT
@@ -149401,15 +149441,15 @@
149441 /* This block is run for the first row of each partition */
149442 s.regArg = windowInitAccum(pParse, pMWin);
149443
149444 if( regStart ){
149445 sqlite3ExprCode(pParse, pMWin->pStart, regStart);
149446 windowCheckValue(pParse, regStart, 0 + (pMWin->eFrmType==TK_RANGE?3:0));
149447 }
149448 if( regEnd ){
149449 sqlite3ExprCode(pParse, pMWin->pEnd, regEnd);
149450 windowCheckValue(pParse, regEnd, 1 + (pMWin->eFrmType==TK_RANGE?3:0));
149451 }
149452
149453 if( pMWin->eFrmType!=TK_RANGE && pMWin->eStart==pMWin->eEnd && regStart ){
149454 int op = ((pMWin->eStart==TK_FOLLOWING) ? OP_Ge : OP_Le);
149455 int addrGe = sqlite3VdbeAddOp3(v, op, regStart, 0, regEnd);
@@ -153724,11 +153764,11 @@
153764 **
153765 ** simplify to constants 0 (false) and 1 (true), respectively,
153766 ** regardless of the value of expr1.
153767 */
153768 sqlite3ExprUnmapAndDelete(pParse, yymsp[-4].minor.yy46);
153769 yymsp[-4].minor.yy46 = sqlite3Expr(pParse->db, TK_INTEGER, yymsp[-3].minor.yy32 ? "1" : "0");
153770 }else{
153771 yymsp[-4].minor.yy46 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy46, 0);
153772 if( yymsp[-4].minor.yy46 ){
153773 yymsp[-4].minor.yy46->x.pList = yymsp[-1].minor.yy138;
153774 sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy46);
@@ -220196,11 +220236,11 @@
220236 int nArg, /* Number of args */
220237 sqlite3_value **apUnused /* Function arguments */
220238 ){
220239 assert( nArg==0 );
220240 UNUSED_PARAM2(nArg, apUnused);
220241 sqlite3_result_text(pCtx, "fts5: 2019-09-25 18:44:49 36d35dbd5a80dc4a149ed7409cc4b43712622fc4c6a8915b4fbb62fd1d6b7763", -1, SQLITE_TRANSIENT);
220242 }
220243
220244 /*
220245 ** Return true if zName is the extension on one of the shadow tables used
220246 ** by this module.
@@ -224964,12 +225004,12 @@
225004 }
225005 #endif /* SQLITE_CORE */
225006 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
225007
225008 /************** End of stmt.c ************************************************/
225009 #if __LINE__!=225009
225010 #undef SQLITE_SOURCE_ID
225011 #define SQLITE_SOURCE_ID "2019-09-26 16:57:42 49073b7003330027303c4c776e9f85112f8b99b89f848fec3f953eba501dalt2"
225012 #endif
225013 /* Return the source-id for this library */
225014 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
225015 /************************** End of sqlite3.c ******************************/
225016
+1 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123123
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124124
** [sqlite_version()] and [sqlite_source_id()].
125125
*/
126126
#define SQLITE_VERSION "3.30.0"
127127
#define SQLITE_VERSION_NUMBER 3030000
128
-#define SQLITE_SOURCE_ID "2019-09-21 17:31:03 8ea1dc727d391b15d0c4fa858ff68d5b8a63dde46408f24027dac8d28f044cbd"
128
+#define SQLITE_SOURCE_ID "2019-09-26 16:57:42 49073b7003330027303c4c776e9f85112f8b99b89f848fec3f953eba501d7505"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
134134
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.30.0"
127 #define SQLITE_VERSION_NUMBER 3030000
128 #define SQLITE_SOURCE_ID "2019-09-21 17:31:03 8ea1dc727d391b15d0c4fa858ff68d5b8a63dde46408f24027dac8d28f044cbd"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
134
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.30.0"
127 #define SQLITE_VERSION_NUMBER 3030000
128 #define SQLITE_SOURCE_ID "2019-09-26 16:57:42 49073b7003330027303c4c776e9f85112f8b99b89f848fec3f953eba501d7505"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
134
--- www/serverext.wiki
+++ www/serverext.wiki
@@ -295,7 +295,7 @@
295295
then additional diagnostic information may be included in the output.
296296
297297
If the /ext page has a "fossil-ext-debug=1" query parameter and if
298298
the requester is logged in as a user with Debug privilege, then the
299299
CGI output is returned verbatim, as text/plain and with the original
300
-header intact. This is useful for trying diagnosing problems with the
300
+header intact. This is useful for diagnosing problems with the
301301
CGI script.
302302
--- www/serverext.wiki
+++ www/serverext.wiki
@@ -295,7 +295,7 @@
295 then additional diagnostic information may be included in the output.
296
297 If the /ext page has a "fossil-ext-debug=1" query parameter and if
298 the requester is logged in as a user with Debug privilege, then the
299 CGI output is returned verbatim, as text/plain and with the original
300 header intact. This is useful for trying diagnosing problems with the
301 CGI script.
302
--- www/serverext.wiki
+++ www/serverext.wiki
@@ -295,7 +295,7 @@
295 then additional diagnostic information may be included in the output.
296
297 If the /ext page has a "fossil-ext-debug=1" query parameter and if
298 the requester is logged in as a user with Debug privilege, then the
299 CGI output is returned verbatim, as text/plain and with the original
300 header intact. This is useful for diagnosing problems with the
301 CGI script.
302

Keyboard Shortcuts

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