aboutsummaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/insert.c4
-rw-r--r--src/sqliteInt.h2
-rw-r--r--src/upsert.c15
3 files changed, 13 insertions, 8 deletions
diff --git a/src/insert.c b/src/insert.c
index 4f9e43b9e..c5c92d6b7 100644
--- a/src/insert.c
+++ b/src/insert.c
@@ -1580,7 +1580,7 @@ void sqlite3GenerateConstraintChecks(
}
#ifndef SQLITE_OMIT_UPSERT
case OE_Update: {
- sqlite3UpsertDoUpdate(pParse, pUpsert, pTab, 0, iDataCur, 0);
+ sqlite3UpsertDoUpdate(pParse, pUpsert, pTab, 0, iDataCur);
/* Fall through */
}
#endif
@@ -1787,7 +1787,7 @@ void sqlite3GenerateConstraintChecks(
}
#ifndef SQLITE_OMIT_UPSERT
case OE_Update: {
- sqlite3UpsertDoUpdate(pParse, pUpsert, pTab, pIdx, iDataCur, iIdxCur);
+ sqlite3UpsertDoUpdate(pParse, pUpsert, pTab, pIdx, iIdxCur+ix);
/* Fall through */
}
#endif
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index 1a5fc5e5a..c0d00270d 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -4293,7 +4293,7 @@ const char *sqlite3JournalModename(int);
void sqlite3UpsertDelete(sqlite3*,Upsert*);
Upsert *sqlite3UpsertDup(sqlite3*,Upsert*);
int sqlite3UpsertAnalyzeTarget(Parse*,SrcList*,Upsert*);
- void sqlite3UpsertDoUpdate(Parse*,Upsert*,Table*,Index*,int,int);
+ void sqlite3UpsertDoUpdate(Parse*,Upsert*,Table*,Index*,int);
#else
#define sqlite3UpsertNew(x,y,z,w) ((Upsert*)0)
#define sqlite3UpsertDelete(x,y)
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);