1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-11 01:42:22 +03:00

Get the ON CONFLICT DO NOTHING form of upsert working by mapping it

into INSERT OR IGNORE.

FossilOrigin-Name: d07f05e98bb9ce0f9b46db159d9df161b7499d6face6a5299ecd2d00a94fb8d0
This commit is contained in:
drh
2018-04-13 15:14:33 +00:00
parent d5af54207d
commit c8a0c90b62
5 changed files with 52 additions and 29 deletions

View File

@@ -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