B 5ee3c27e20d12a126fb773b428bb864102b949a5b26a8d5c523753dcedf4be10
-C Fix\sa\sproblem\sin\sSQLITE_ENABLE_HIDDEN_COLUMN\sbuilds\soccuring\swhen\san\sUPDATE...FROM\sfired\san\sINSTEAD\sOF\strigger.
-D 2020-07-15T15:32:59.655
+C Fix\sproblems\sthat\scould\soccur\sif\sa\stable\swith\sthe\ssame\sname\sas\sthe\stable\sbeing\supdated\sappeared\sin\sthe\sFROM\sclause\sof\san\sUPDATE\sstatement.
+D 2020-07-15T18:30:01.625
F src/alter.c c63fb72ae0ca39175996fcf7008d44022a7ea99e03c0af3e1d968505ceff7120
F src/attach.c 0b11e00c166b622c84ec176773b1d691c61ad07d247809e3e1635d4e99e71d30
F src/btree.c b8b0e80c8bbe4e1fb35ae559e9e9aa009799c20cf12f159ebb503b05be1fab9b
F src/parse.y ecb9abdd79ec86c8dca7cb126bbdcf322c0e282f87a6d0d734ea5f2c57ced516
-F src/resolve.c 04f4710d3ab0070073b60b5b963158dadfbd049db55d10742d9fbd3f28a3f4b8
+F src/resolve.c 2dd6821aac2cd27de9fcf6aa6d1f8c41b4b5841c9bc58bf1c9109008009a3a2e
F src/select.c a48570f614f777d02dd7f419789944225432a9231b2dbca863411ac19e5fb683
F src/sqliteInt.h e2684c4ba7ee9c0a0529ae2eb847cc5bf923e4104a9d0944bf3d9d151856b6ab
F src/trigger.c 6ff9c64a06e6354df8eba08ae18bc809e79931175d39dda32bf1101adee238e5
-F src/update.c d9b7f86c8d694f5131152b4c216ba257844a8bf63ec4bfe71dbe511cad8a7600
+F src/update.c d254339ce702ca08e4761efcc3b841895f09e6a144f4d2b65f4da9e872f9825d
F src/where.c 35cb38d45294118e484fd3a8011aaee8ebe96b28855a6913575a7fe3722d7af5
F test/altertab3.test d0d51e652aaa11e37de1f1215181d88334fefcb185f3b9bd91e06e98260c4694
F test/decimal.test fcf403fd5585f47342234e153c4a4338cd737b8e0884ac66fc484df47dbcf1a7
F test/triggerupfrom.test d25961fa70a99b6736193da7b49a36d8c1d28d56188f0be6406d4366315cd6e4
F test/upfrom1.tcl df984cb88010af1555812af55e9db44c4df50677395b45d1f30b69b1b6c07b73
F test/upfrom1.test 2ba1ed45b4a2161fc79f234b9ce4300b0d3deba545e3f23b938fb3ebdbf8758d
-F test/upfrom3.test 2619374c4806913414cc39514630d85bb12489a5f09a5ebdf6fad0fb4df242e2
-P 53b8b507a10364f5d580655d89c950a5f14c2a8114625fd8749d77f289413b22
-R 50049e7505da24bcfa1309cf7e88265f
+F test/upfrom3.test 3890e1fc372aaf70ca88ec2650f4574b169368a5a63770245a45a28f1524b1b9
+P 5176cb7a6a4e8cfa1973aaae46fcd7d39baedb70ae20bfacc82d62ca39fb0aa3
+R 5994321bbabb2542296f6db00df19961
U dan
-Z 6a5f095ea5bbd01f6db55318ec51bead
+Z 41a21fcf4a769b492a5346939daeca22
}
/*
-** This function generates VM code to run the query:
+** Allocate and return a pointer to an expression of type TK_ROW with
+** Expr.iColumn set to value (iCol+1). The resolver will modify the
+** expression to be a TK_COLUMN reading column iCol of the first
+** table in the source-list (pSrc->a[0]).
+*/
+static Expr *exprRowColumn(Parse *pParse, int iCol){
+ Expr *pRet = sqlite3PExpr(pParse, TK_ROW, 0, 0);
+ if( pRet ) pRet->iColumn = iCol+1;
+ return pRet;
+}
+
+/*
+** Assuming both the pLimit and pOrderBy parameters are NULL, this function
+** generates VM code to run the query:
**
-** SELECT <other-columns>, pChanges FROM pTabList WHERE pWhere
+** SELECT <other-columns>, pChanges FROM pTabList WHERE pWhere
**
** and write the results to the ephemeral table already opened as cursor
** iEph. None of pChanges, pTabList or pWhere are modified or consumed by
** this function, they must be deleted by the caller.
**
+** Or, if pLimit and pOrderBy are not NULL, and pTab is not a view:
+**
+** SELECT <other-columns>, pChanges FROM pTabList
+** WHERE pWhere
+** GROUP BY <other-columns>
+** ORDER BY pOrderBy LIMIT pLimit
+**
+** If pTab is a view, the GROUP BY clause is omitted.
+**
** Exactly how results are written to table iEph, and exactly what
** the <other-columns> in the query above are is determined by the type
** of table pTabList->a[0].pTab.
** rowid value in <other-columns> is used as the integer key, and the
** remaining fields make up the table record.
*/
-static void updatePopulateEphTable(
+static void updateFromSelect(
Parse *pParse, /* Parse context */
int iEph, /* Cursor for open eph. table */
Index *pPk, /* PK if table 0 is WITHOUT ROWID */
SelectDest dest;
Select *pSelect = 0;
ExprList *pList = 0;
- ExprList *pGroupBy = 0;
+ ExprList *pGrp = 0;
sqlite3 *db = pParse->db;
Table *pTab = pTabList->a[0].pTab;
SrcList *pSrc;
}
if( pPk ){
for(i=0; i<pPk->nKeyCol; i++){
- Expr *pNew = sqlite3PExpr(pParse, TK_DOT,
- sqlite3Expr(db, TK_ID, pTab->zName),
- sqlite3Expr(db, TK_ID, pTab->aCol[pPk->aiColumn[i]].zName)
- );
+ Expr *pNew = exprRowColumn(pParse, pPk->aiColumn[i]);
if( pLimit ){
- pGroupBy = sqlite3ExprListAppend(pParse, pGroupBy,
- sqlite3ExprDup(db, pNew, 0)
- );
+ pGrp = sqlite3ExprListAppend(pParse, pGrp, sqlite3ExprDup(db, pNew, 0));
}
pList = sqlite3ExprListAppend(pParse, pList, pNew);
}
eDest = SRT_Upfrom;
}else if( pTab->pSelect ){
- pList = sqlite3ExprListAppend(pParse, pList,
- sqlite3PExpr(pParse, TK_DOT,
- sqlite3Expr(db, TK_ID, pTab->zName),
- sqlite3PExpr(pParse, TK_ASTERISK, 0, 0)
- ));
+ for(i=0; i<pTab->nCol; i++){
+ pList = sqlite3ExprListAppend(pParse, pList, exprRowColumn(pParse, i));
+ }
eDest = SRT_Table;
}else{
eDest = IsVirtual(pTab) ? SRT_Table : SRT_Upfrom;
- pList = sqlite3ExprListAppend(pParse, pList,
- sqlite3PExpr(pParse, TK_ROW, 0, 0)
- );
+ pList = sqlite3ExprListAppend(pParse, 0, sqlite3PExpr(pParse,TK_ROW,0,0));
if( pLimit ){
- pGroupBy = sqlite3ExprListAppend(pParse, pGroupBy,
- sqlite3PExpr(pParse, TK_ROW, 0, 0)
- );
+ pGrp = sqlite3ExprListAppend(pParse, 0, sqlite3PExpr(pParse,TK_ROW,0,0));
}
}
assert( pChanges || db->mallocFailed );
}
}
pSelect = sqlite3SelectNew(pParse, pList,
- pSrc, pWhere2, pGroupBy, 0, pOrderBy2, SF_IncludeHidden, pLimit2
+ pSrc, pWhere2, pGrp, 0, pOrderBy2, SF_IncludeHidden, pLimit2
);
sqlite3SelectDestInit(&dest, eDest, iEph);
dest.iSDParm2 = (pPk ? pPk->nKeyCol : -1);
}
}
if( nChangeFrom ){
- updatePopulateEphTable(
+ updateFromSelect(
pParse, iEph, pPk, pChanges, pTabList, pWhere, pOrderBy, pLimit
);
#ifndef SQLITE_OMIT_SUBQUERY
regArg = pParse->nMem + 1;
pParse->nMem += nArg;
if( pSrc->nSrc>1 ){
- ExprList *pList = 0;
+ Expr *pRow;
+ ExprList *pList;
if( pRowid ){
- pList = sqlite3ExprListAppend(pParse, pList, sqlite3ExprDup(db,pRowid,0));
+ pRow = sqlite3ExprDup(db, pRowid, 0);
}else{
- pList = sqlite3ExprListAppend(pParse, pList,
- sqlite3PExpr(pParse, TK_DOT,
- sqlite3Expr(db, TK_ID, pTab->zName),
- sqlite3Expr(db, TK_ID, "_rowid_")
- ));
+ pRow = sqlite3PExpr(pParse, TK_ROW, 0, 0);
}
+ pList = sqlite3ExprListAppend(pParse, 0, pRow);
+
for(i=0; i<pTab->nCol; i++){
if( aXRef[i]>=0 ){
pList = sqlite3ExprListAppend(pParse, pList,
sqlite3ExprDup(db, pChanges->a[aXRef[i]].pExpr, 0)
);
}else{
- pList = sqlite3ExprListAppend(pParse, pList,
- sqlite3PExpr(pParse, TK_DOT,
- sqlite3Expr(db, TK_ID, pTab->zName),
- sqlite3Expr(db, TK_ID, pTab->aCol[i].zName)
- ));
+ pList = sqlite3ExprListAppend(pParse, pList, exprRowColumn(pParse, i));
}
}
- updatePopulateEphTable(pParse, ephemTab, 0, pList, pSrc, pWhere, 0, 0);
+ updateFromSelect(pParse, ephemTab, 0, pList, pSrc, pWhere, 0, 0);
sqlite3ExprListDelete(db, pList);
eOnePass = ONEPASS_OFF;
}else{