/ Check-in [5216bfb7]
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], a problem discovered by OSSFuzz.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 5216bfb73f1a49bdd879d470de139bf46a212474eaf6f38ad2390536d66a2afd
User & Date: drh 2017-07-30 18:40:52
References
2017-07-31
12:19
Correctly handle an "INTEGER PRIMARY KEY UNIQUE" column in a WITHOUT ROWID table. This is a fix for ticket [bc115541132dad136], cherry-picked from check-in [5216bfb73f1a49bdd8] check-in: 322a2ede user: drh tags: branch-3.19
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
Context
2017-07-31
12:19
Correctly handle an "INTEGER PRIMARY KEY UNIQUE" column in a WITHOUT ROWID table. This is a fix for ticket [bc115541132dad136], cherry-picked from check-in [5216bfb73f1a49bdd8] check-in: 322a2ede user: drh tags: branch-3.19
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
19:50
Add the schema6.test module for demonstrating schemas that generate identical and different content. check-in: ac1da06a user: drh tags: trunk
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
22:22
Update Tcl version used by the TclKit batch tool for MSVC. check-in: bcec155e user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

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

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