diff options
author | drh <drh@noemail.net> | 2018-04-14 22:35:34 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2018-04-14 22:35:34 +0000 |
commit | e966a36cf4f771b200a5cfbf3714d4a33679c9d4 (patch) | |
tree | 410f603c4cfcfd66cd14b933e346f00b234404f4 /src/upsert.c | |
parent | 096fd476c1ebb53a8add1f89176bad80eadbd880 (diff) | |
download | sqlite-e966a36cf4f771b200a5cfbf3714d4a33679c9d4.tar.gz sqlite-e966a36cf4f771b200a5cfbf3714d4a33679c9d4.zip |
Get upsert working on WITHOUT ROWID tables.
FossilOrigin-Name: d3c53fd3177946f50137d48da871de43d78d10ef9990cc4ea6750f7020f89b6a
Diffstat (limited to 'src/upsert.c')
-rw-r--r-- | src/upsert.c | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/src/upsert.c b/src/upsert.c index 230cfb060..a92824f8f 100644 --- a/src/upsert.c +++ b/src/upsert.c @@ -221,14 +221,37 @@ void sqlite3UpsertDoUpdate( pE2->affinity = SQLITE_AFF_INTEGER; } pWhere = sqlite3ExprAnd(db,pWhere,sqlite3PExpr(pParse, TK_EQ, pE1, pE2)); - pSrc = sqlite3SrcListDup(db, pUpsert->pUpsertSrc, 0); - sqlite3Update(pParse, pSrc, - sqlite3ExprListDup(db, pUpsert->pUpsertSet, 0), - pWhere, OE_Abort, 0, 0); }else{ /* a WITHOUT ROWID table */ - sqlite3ExprDelete(db, pWhere); + int i, j; + int iTab = pParse->nTab+1; + Index *pX; + for(pX=pTab->pIndex; ALWAYS(pX) && !IsPrimaryKeyIndex(pX); pX=pX->pNext){ + iTab++; + } + for(i=0; i<pIdx->nKeyCol; i++){ + regKey = ++pParse->nMem; + sqlite3VdbeAddOp3(v, OP_Column, iDataCur, i, regKey); + j = pIdx->aiColumn[i]; + VdbeComment((v, "%s", pTab->aCol[j].zName)); + pE1 = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0); + if( pE1 ){ + pE1->pTab = pTab; + pE1->iTable = iTab; + pE1->iColumn = j; + } + pE2 = sqlite3ExprAlloc(db, TK_REGISTER, 0, 0); + if( pE2 ){ + pE2->iTable = regKey; + pE2->affinity = pTab->zColAff[j]; + } + pWhere = sqlite3ExprAnd(db,pWhere,sqlite3PExpr(pParse, TK_EQ, pE1, pE2)); + } } + pSrc = sqlite3SrcListDup(db, pUpsert->pUpsertSrc, 0); + sqlite3Update(pParse, pSrc, + sqlite3ExprListDup(db, pUpsert->pUpsertSet, 0), + pWhere, OE_Abort, 0, 0); VdbeNoopComment((v, "End DO UPDATE of UPSERT")); } |