/ Check-in [359725ab]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix UPSERT so that it plays nicely with AUTOINCREMENT.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 359725ab36339b443b7745e84f6d27991038ceb063c653805dde17f3eb5a03c5
User & Date: drh 2018-04-21 03:06:29
Context
2018-04-21
13:51
Add the %extra_context directive to lemon, as an alternative to %extra_argument. Use this to improve the performance of the parser. check-in: be47a6f5 user: drh tags: trunk
03:06
Fix UPSERT so that it plays nicely with AUTOINCREMENT. check-in: 359725ab user: drh tags: trunk
2018-04-20
20:47
Add the -dDIRECTORY command-line option to LEMON. check-in: 9cd20475 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/update.c.

   751    751     }
   752    752     sqlite3VdbeResolveLabel(v, labelBreak);
   753    753   
   754    754     /* Update the sqlite_sequence table by storing the content of the
   755    755     ** maximum rowid counter values recorded while inserting into
   756    756     ** autoincrement tables.
   757    757     */
   758         -  if( pParse->nested==0 && pParse->pTriggerTab==0 ){
          758  +  if( pParse->nested==0 && pParse->pTriggerTab==0 && pUpsert==0 ){
   759    759       sqlite3AutoincrementEnd(pParse);
   760    760     }
   761    761   
   762    762     /*
   763    763     ** Return the number of rows that were changed, if we are tracking
   764    764     ** that information.
   765    765     */

Changes to test/autoinc.test.

   671    671     CREATE TABLE t10a(a INTEGER PRIMARY KEY AUTOINCREMENT, b UNIQUE);
   672    672     INSERT INTO t10a VALUES(888,9999);
   673    673     CREATE TABLE t10b(x INTEGER PRIMARY KEY AUTOINCREMENT, y UNIQUE);
   674    674     INSERT INTO t10b SELECT * FROM t10a;
   675    675     SELECT * FROM sqlite_sequence;
   676    676   } {t10a 888 t10b 888}
   677    677   
   678         -
          678  +# 2018-04-21 autoincrement does not cause problems for upsert
          679  +#
          680  +do_execsql_test autoinc-11.1 {
          681  +  CREATE TABLE t11(a INTEGER PRIMARY KEY AUTOINCREMENT,b UNIQUE);
          682  +  INSERT INTO t11(a,b) VALUES(2,3),(5,6),(4,3),(1,2)
          683  +    ON CONFLICT(b) DO UPDATE SET a=a+1000;
          684  +  SELECT seq FROM sqlite_sequence WHERE name='t11';
          685  +} {5}
   679    686   
   680    687   finish_test