aboutsummaryrefslogtreecommitdiff
path: root/src/insert.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2018-04-13 15:14:33 +0000
committerdrh <drh@noemail.net>2018-04-13 15:14:33 +0000
commitc8a0c90b62bb4dc1782b079d9e7d315f49d8bd9a (patch)
tree71f3839c2c5ba0301f5f188ffdc49502484a3e40 /src/insert.c
parentd5af54207db43d5f5329ad545685a9dc71609c56 (diff)
downloadsqlite-c8a0c90b62bb4dc1782b079d9e7d315f49d8bd9a.tar.gz
sqlite-c8a0c90b62bb4dc1782b079d9e7d315f49d8bd9a.zip
Get the ON CONFLICT DO NOTHING form of upsert working by mapping it
into INSERT OR IGNORE. FossilOrigin-Name: d07f05e98bb9ce0f9b46db159d9df161b7499d6face6a5299ecd2d00a94fb8d0
Diffstat (limited to 'src/insert.c')
-rw-r--r--src/insert.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/insert.c b/src/insert.c
index f399f1417..df2f3f6ea 100644
--- a/src/insert.c
+++ b/src/insert.c
@@ -1396,6 +1396,15 @@ void sqlite3GenerateConstraintChecks(
VdbeCoverage(v);
}
+ /* figure out whether or not upsert applies in this case */
+ if( pUpsert && (pUpsert->pUpsertTarget==0 || pUpsert->pUpsertIdx==0) ){
+ if( pUpsert->pUpsertSet==0 ){
+ onError = OE_Ignore; /* DO NOTHING is the same as INSERT OR IGNORE */
+ }else{
+ onError = OE_Update; /* DO UPDATE */
+ }
+ }
+
/* If the response to a rowid conflict is REPLACE but the response
** to some other UNIQUE constraint is FAIL or IGNORE, then we need
** to defer the running of the rowid conflict checking until after
@@ -1415,7 +1424,6 @@ void sqlite3GenerateConstraintChecks(
sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, addrRowidOk, regNewData);
VdbeCoverage(v);
- /* Generate code that deals with a rowid collision */
switch( onError ){
default: {
onError = OE_Abort;
@@ -1478,7 +1486,6 @@ void sqlite3GenerateConstraintChecks(
break;
}
case OE_Ignore: {
- /*assert( seenReplace==0 );*/
sqlite3VdbeGoto(v, ignoreDest);
break;
}
@@ -1569,6 +1576,15 @@ void sqlite3GenerateConstraintChecks(
onError = OE_Abort;
}
+ /* Figure out if the upsert clause applies to this index */
+ if( pUpsert && (pUpsert->pUpsertTarget==0 || pUpsert->pUpsertIdx==pIdx) ){
+ if( pUpsert->pUpsertSet==0 ){
+ onError = OE_Ignore; /* DO NOTHING is the same as INSERT OR IGNORE */
+ }else{
+ onError = OE_Update; /* DO UPDATE */
+ }
+ }
+
/* Collision detection may be omitted if all of the following are true:
** (1) The conflict resolution algorithm is REPLACE
** (2) The table is a WITHOUT ROWID table