Skip to content

Commit

Permalink
Fix UPSERT so that it plays nicely with AUTOINCREMENT.
Browse files Browse the repository at this point in the history
  • Loading branch information
D. Richard Hipp committed Apr 21, 2018
1 parent 736e50b commit b3b0ea8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/update.c
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ void sqlite3Update(
** maximum rowid counter values recorded while inserting into
** autoincrement tables.
*/
if( pParse->nested==0 && pParse->pTriggerTab==0 ){
if( pParse->nested==0 && pParse->pTriggerTab==0 && pUpsert==0 ){
sqlite3AutoincrementEnd(pParse);
}

Expand Down
9 changes: 8 additions & 1 deletion test/autoinc.test
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,13 @@ do_execsql_test autoinc-10.1 {
SELECT * FROM sqlite_sequence;
} {t10a 888 t10b 888}


# 2018-04-21 autoincrement does not cause problems for upsert
#
do_execsql_test autoinc-11.1 {
CREATE TABLE t11(a INTEGER PRIMARY KEY AUTOINCREMENT,b UNIQUE);
INSERT INTO t11(a,b) VALUES(2,3),(5,6),(4,3),(1,2)
ON CONFLICT(b) DO UPDATE SET a=a+1000;
SELECT seq FROM sqlite_sequence WHERE name='t11';
} {5}

finish_test

0 comments on commit b3b0ea8

Please sign in to comment.