aboutsummaryrefslogtreecommitdiff
path: root/src/upsert.c
diff options
context:
space:
mode:
authordan <dan@noemail.net>2018-04-17 18:16:10 +0000
committerdan <dan@noemail.net>2018-04-17 18:16:10 +0000
commit2cc00423a0696c866c49ea6debc68d83f7da17a8 (patch)
treead58305d2bc5bf5e0a30caf2b35345b32834eb0e /src/upsert.c
parent5015c9b50e19987042ee19a33349b57fd58fd847 (diff)
downloadsqlite-2cc00423a0696c866c49ea6debc68d83f7da17a8.tar.gz
sqlite-2cc00423a0696c866c49ea6debc68d83f7da17a8.zip
Add some more simple test cases for UPSERT. And a minor fix.
FossilOrigin-Name: 27cd3b2fb2ad0cf2b36741bd1057cb7973954d40456e9db158261a38b049d2b5
Diffstat (limited to 'src/upsert.c')
-rw-r--r--src/upsert.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/upsert.c b/src/upsert.c
index 053bc924a..e1af0a0b7 100644
--- a/src/upsert.c
+++ b/src/upsert.c
@@ -182,14 +182,19 @@ int sqlite3UpsertAnalyzeTarget(
/*
** Generate bytecode that does an UPDATE as part of an upsert.
+**
+** If pIdx is NULL, then the UNIQUE constraint that failed was the IPK.
+** In this case parameter iCur is a cursor open on the table b-tree that
+** currently points to the conflicting table row. Otherwise, if pIdx
+** is not NULL, then pIdx is the constraint that failed and iCur is a
+** cursor points to the conflicting row.
*/
void sqlite3UpsertDoUpdate(
Parse *pParse, /* The parsing and code-generating context */
Upsert *pUpsert, /* The ON CONFLICT clause for the upsert */
Table *pTab, /* The table being updated */
Index *pIdx, /* The UNIQUE constraint that failed */
- int iDataCur, /* Cursor for the pTab, table being updated */
- int iIdxCur /* Cursor for pIdx */
+ int iCur /* Cursor for pIdx (or pTab if pIdx==NULL) */
){
Vdbe *v = pParse->pVdbe;
sqlite3 *db = pParse->db;
@@ -205,9 +210,9 @@ void sqlite3UpsertDoUpdate(
/* We are dealing with an IPK */
regKey = ++pParse->nMem;
if( pIdx ){
- sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, regKey);
+ sqlite3VdbeAddOp2(v, OP_IdxRowid, iCur, regKey);
}else{
- sqlite3VdbeAddOp2(v, OP_Rowid, iDataCur, regKey);
+ sqlite3VdbeAddOp2(v, OP_Rowid, iCur, regKey);
}
pE1 = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0);
if( pE1 ){
@@ -231,7 +236,7 @@ void sqlite3UpsertDoUpdate(
}
for(i=0; i<pIdx->nKeyCol; i++){
regKey = ++pParse->nMem;
- sqlite3VdbeAddOp3(v, OP_Column, iDataCur, i, regKey);
+ sqlite3VdbeAddOp3(v, OP_Column, iCur, i, regKey);
j = pIdx->aiColumn[i];
VdbeComment((v, "%s", pTab->aCol[j].zName));
pE1 = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0);