diff options
author | dan <dan@noemail.net> | 2020-05-01 18:43:49 +0000 |
---|---|---|
committer | dan <dan@noemail.net> | 2020-05-01 18:43:49 +0000 |
commit | 7465787b97a0a09841e343630a07ba80f1399e4a (patch) | |
tree | 23e5e03f7b9778f933cdf8590810ae323831d2dc /src | |
parent | 8b023cf5928f9c728ec8445144a47e1705546c24 (diff) | |
download | sqlite-7465787b97a0a09841e343630a07ba80f1399e4a.tar.gz sqlite-7465787b97a0a09841e343630a07ba80f1399e4a.zip |
Fix problems with UPDATE...FROM statements that modify rowid or primary-key values.
FossilOrigin-Name: 623ab585d1aa1bdde2df17f1936aa4eec2d997b274acc5c7b291d9566a9ec2c5
Diffstat (limited to 'src')
-rw-r--r-- | src/update.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/update.c b/src/update.c index 0b98e7017..7aa9fee51 100644 --- a/src/update.c +++ b/src/update.c @@ -285,6 +285,7 @@ void sqlite3Update( u8 chngRowid; /* Rowid changed in a normal table */ u8 chngKey; /* Either chngPk or chngRowid */ Expr *pRowidExpr = 0; /* Expression defining the new record number */ + int iRowidExpr = -1; AuthContext sContext; /* The authorization context */ NameContext sNC; /* The name-context to resolve expressions in */ int iDb; /* Database containing the table being updated */ @@ -430,6 +431,7 @@ void sqlite3Update( if( j==pTab->iPKey ){ chngRowid = 1; pRowidExpr = pChanges->a[i].pExpr; + iRowidExpr = i; }else if( pPk && (pTab->aCol[j].colFlags & COLFLAG_PRIMKEY)!=0 ){ chngPk = 1; } @@ -452,6 +454,7 @@ void sqlite3Update( j = -1; chngRowid = 1; pRowidExpr = pChanges->a[i].pExpr; + iRowidExpr = i; }else{ sqlite3ErrorMsg(pParse, "no such column: %s", pChanges->a[i].zEName); pParse->checkSchema = 1; @@ -649,6 +652,8 @@ void sqlite3Update( if( nChangeFrom ){ sqlite3MultiWrite(pParse); eOnePass = ONEPASS_OFF; + nKey = nPk; + regKey = iPk; }else{ if( pUpsert ){ /* If this is an UPSERT, then all cursors have already been opened by @@ -810,7 +815,12 @@ void sqlite3Update( ** already populated. */ assert( chngKey || pTrigger || hasFK || regOldRowid==regNewRowid ); if( chngRowid ){ - sqlite3ExprCode(pParse, pRowidExpr, regNewRowid); + assert( iRowidExpr>=0 ); + if( nChangeFrom==0 ){ + sqlite3ExprCode(pParse, pRowidExpr, regNewRowid); + }else{ + sqlite3VdbeAddOp3(v, OP_Column, iEph, iRowidExpr, regNewRowid); + } sqlite3VdbeAddOp1(v, OP_MustBeInt, regNewRowid); VdbeCoverage(v); } @@ -909,15 +919,7 @@ void sqlite3Update( ** documentation. */ if( pPk ){ - int p3, p4; - if( nChangeFrom ){ - p3 = iPk; - p4 = nPk; - }else{ - p3 = regKey; - p4 = nKey; - } - sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue, p3, p4); + sqlite3VdbeAddOp4Int(v, OP_NotFound,iDataCur,labelContinue,regKey,nKey); VdbeCoverage(v); }else{ sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue,regOldRowid); |