/ Check-in [5c8cb1ff]
Login

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

Overview
Comment:Correctly handle an "INTEGER PRIMARY KEY UNIQUE" column in a WITHOUT ROWID table. This is a fix for ticket [bc115541132dad136] cherry-picked from [5216bfb73f1a49bdd].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | branch-3.20
Files: files | file ages | folders
SHA3-256:5c8cb1ff5da872fb5ab3f77f678b9df3b68525433f6d5d918f2911a5622bdd14
User & Date: drh 2017-07-30 20:30:36
Context
2017-07-31
17:40
More consistent column names. Cherry-pick of [09834279] and [0c38dde45] as a fix for ticket [de3403bf5ae]. check-in: be0e24a0 user: drh tags: branch-3.20
2017-07-30
20:30
Correctly handle an "INTEGER PRIMARY KEY UNIQUE" column in a WITHOUT ROWID table. This is a fix for ticket [bc115541132dad136] cherry-picked from [5216bfb73f1a49bdd]. check-in: 5c8cb1ff user: drh tags: branch-3.20
18:40
Correctly handle an "INTEGER PRIMARY KEY UNIQUE" column in a WITHOUT ROWID table. This is a fix for ticket [bc115541132dad136], a problem discovered by OSSFuzz. check-in: 5216bfb7 user: drh tags: trunk
2017-07-28
12:20
Fix a punctuation typo in the documentation for sqlite3_step(). No changes to code. check-in: c965b757 user: drh tags: branch-3.20
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

  1734   1734                          SQLITE_IDXTYPE_PRIMARYKEY);
  1735   1735       if( db->mallocFailed ) return;
  1736   1736       pPk = sqlite3PrimaryKeyIndex(pTab);
  1737   1737       pTab->iPKey = -1;
  1738   1738     }else{
  1739   1739       pPk = sqlite3PrimaryKeyIndex(pTab);
  1740   1740   
  1741         -    /* Bypass the creation of the PRIMARY KEY btree and the sqlite_master
  1742         -    ** table entry. This is only required if currently generating VDBE
  1743         -    ** code for a CREATE TABLE (not when parsing one as part of reading
  1744         -    ** a database schema).  */
  1745         -    if( v ){
  1746         -      assert( db->init.busy==0 );
  1747         -      sqlite3VdbeChangeOpcode(v, pPk->tnum, OP_Goto);
  1748         -    }
  1749         -
  1750   1741       /*
  1751   1742       ** Remove all redundant columns from the PRIMARY KEY.  For example, change
  1752   1743       ** "PRIMARY KEY(a,b,a,b,c,b,c,d)" into just "PRIMARY KEY(a,b,c,d)".  Later
  1753   1744       ** code assumes the PRIMARY KEY contains no repeated columns.
  1754   1745       */
  1755   1746       for(i=j=1; i<pPk->nKeyCol; i++){
  1756   1747         if( hasColumn(pPk->aiColumn, j, pPk->aiColumn[i]) ){
................................................................................
  1761   1752       }
  1762   1753       pPk->nKeyCol = j;
  1763   1754     }
  1764   1755     assert( pPk!=0 );
  1765   1756     pPk->isCovering = 1;
  1766   1757     if( !db->init.imposterTable ) pPk->uniqNotNull = 1;
  1767   1758     nPk = pPk->nKeyCol;
         1759  +
         1760  +  /* Bypass the creation of the PRIMARY KEY btree and the sqlite_master
         1761  +  ** table entry. This is only required if currently generating VDBE
         1762  +  ** code for a CREATE TABLE (not when parsing one as part of reading
         1763  +  ** a database schema).  */
         1764  +  if( v && pPk->tnum>0 ){
         1765  +    assert( db->init.busy==0 );
         1766  +    sqlite3VdbeChangeOpcode(v, pPk->tnum, OP_Goto);
         1767  +  }
  1768   1768   
  1769   1769     /* The root page of the PRIMARY KEY is the table root page */
  1770   1770     pPk->tnum = pTab->tnum;
  1771   1771   
  1772   1772     /* Update the in-memory representation of all UNIQUE indices by converting
  1773   1773     ** the final rowid column into one or more columns of the PRIMARY KEY.
  1774   1774     */

Changes to test/without_rowid1.test.

   323    323   } {1 {CHECK constraint failed: t70a}}
   324    324   do_catchsql_test 7.3 {
   325    325     CREATE TABLE t70b(
   326    326        a INT CHECK( rowid!=33 ),
   327    327        b TEXT PRIMARY KEY
   328    328     ) WITHOUT ROWID;
   329    329   } {1 {no such column: rowid}}
          330  +
          331  +# 2017-07-30: OSSFuzz discovered that an extra entry was being
          332  +# added in the sqlite_master table for an "INTEGER PRIMARY KEY UNIQUE"
          333  +# WITHOUT ROWID table.  Make sure this has now been fixed.
          334  +#
          335  +db close
          336  +sqlite3 db :memory:
          337  +do_execsql_test 8.1 {
          338  +  CREATE TABLE t1(x INTEGER PRIMARY KEY UNIQUE, b) WITHOUT ROWID;
          339  +  CREATE INDEX t1x ON t1(x);
          340  +  INSERT INTO t1(x,b) VALUES('funny','buffalo');
          341  +  SELECT type, name, '|' FROM sqlite_master;
          342  +} {table t1 | index t1x |}
          343  +
   330    344   
   331    345     
   332    346   finish_test