/ Check-in [b1abb2b0]
Login

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

Overview
Comment:Throw an error if AUTOINCREMENT appears in a WITHOUT ROWID table. Updates to API documentation to discuss WITHOUT ROWID.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: b1abb2b078d1cb9ec5fbd7f98221914b93632e9f
User & Date: drh 2013-11-09 18:15:35
Context
2013-11-09
19:47
Updates to requirements marks. No changes to code. check-in: 8a036628 user: drh tags: trunk
18:15
Throw an error if AUTOINCREMENT appears in a WITHOUT ROWID table. Updates to API documentation to discuss WITHOUT ROWID. check-in: b1abb2b0 user: drh tags: trunk
2013-11-08
17:13
Fix harmless compiler warnings. check-in: 0077c077 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

  1765   1765     */
  1766   1766     if( db->init.busy ){
  1767   1767       p->tnum = db->init.newTnum;
  1768   1768     }
  1769   1769   
  1770   1770     /* Special processing for WITHOUT ROWID Tables */
  1771   1771     if( tabOpts & TF_WithoutRowid ){
         1772  +    if( (p->tabFlags & TF_Autoincrement) ){
         1773  +      sqlite3ErrorMsg(pParse,
         1774  +          "AUTOINCREMENT not allowed on WITHOUT ROWID tables");
         1775  +      return;
         1776  +    }
  1772   1777       if( (p->tabFlags & TF_HasPrimaryKey)==0 ){
  1773         -      sqlite3ErrorMsg(pParse, "no PRIMARY KEY for table %s", p->zName);
         1778  +      sqlite3ErrorMsg(pParse, "PRIMARY KEY missing on table %s", p->zName);
  1774   1779       }else{
  1775   1780         p->tabFlags |= TF_WithoutRowid;
  1776   1781         convertToWithoutRowidTable(pParse, p);
  1777   1782       }
  1778   1783     }
  1779   1784   
  1780   1785     iDb = sqlite3SchemaToIndex(db, p->pSchema);

Changes to src/sqlite.h.in.

  1786   1786   ** integer key called the [ROWID | "rowid"]. ^The rowid is always available
  1787   1787   ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
  1788   1788   ** names are not also used by explicitly declared columns. ^If
  1789   1789   ** the table has a column of type [INTEGER PRIMARY KEY] then that column
  1790   1790   ** is another alias for the rowid.
  1791   1791   **
  1792   1792   ** ^This routine returns the [rowid] of the most recent
  1793         -** successful [INSERT] into the database from the [database connection]
         1793  +** successful [INSERT] into a rowid table from the [database connection]
  1794   1794   ** in the first argument.  ^As of SQLite version 3.7.7, this routines
  1795   1795   ** records the last insert rowid of both ordinary tables and [virtual tables].
  1796         -** ^If no successful [INSERT]s
  1797         -** have ever occurred on that database connection, zero is returned.
         1796  +** ^Inserts into [WITHOUT ROWID] tables are not recorded.
         1797  +** ^If no successful [INSERT]s into rowid tables
         1798  +** have ever occurred on the database connection D, 
         1799  +** then sqlite3_last_insert_rowid(D) returns zero.
  1798   1800   **
  1799   1801   ** ^(If an [INSERT] occurs within a trigger or within a [virtual table]
  1800   1802   ** method, then this routine will return the [rowid] of the inserted
  1801   1803   ** row as long as the trigger or virtual table method is running.
  1802   1804   ** But once the trigger or virtual table method ends, the value returned 
  1803   1805   ** by this routine reverts to what it was before the trigger or virtual
  1804   1806   ** table method began.)^
................................................................................
  4807   4809   void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
  4808   4810   
  4809   4811   /*
  4810   4812   ** CAPI3REF: Data Change Notification Callbacks
  4811   4813   **
  4812   4814   ** ^The sqlite3_update_hook() interface registers a callback function
  4813   4815   ** with the [database connection] identified by the first argument
  4814         -** to be invoked whenever a row is updated, inserted or deleted.
         4816  +** to be invoked whenever a row is updated, inserted or deleted in
         4817  +** a rowid table.
  4815   4818   ** ^Any callback set by a previous call to this function
  4816   4819   ** for the same database connection is overridden.
  4817   4820   **
  4818   4821   ** ^The second argument is a pointer to the function to invoke when a
  4819         -** row is updated, inserted or deleted.
         4822  +** row is updated, inserted or deleted in a rowid table.
  4820   4823   ** ^The first argument to the callback is a copy of the third argument
  4821   4824   ** to sqlite3_update_hook().
  4822   4825   ** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE],
  4823   4826   ** or [SQLITE_UPDATE], depending on the operation that caused the callback
  4824   4827   ** to be invoked.
  4825   4828   ** ^The third and fourth arguments to the callback contain pointers to the
  4826   4829   ** database and table name containing the affected row.
  4827   4830   ** ^The final callback parameter is the [rowid] of the row.
  4828   4831   ** ^In the case of an update, this is the [rowid] after the update takes place.
  4829   4832   **
  4830   4833   ** ^(The update hook is not invoked when internal system tables are
  4831   4834   ** modified (i.e. sqlite_master and sqlite_sequence).)^
         4835  +** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.
  4832   4836   **
  4833   4837   ** ^In the current implementation, the update hook
  4834   4838   ** is not invoked when duplication rows are deleted because of an
  4835   4839   ** [ON CONFLICT | ON CONFLICT REPLACE] clause.  ^Nor is the update hook
  4836   4840   ** invoked when rows are deleted using the [truncate optimization].
  4837   4841   ** The exceptions defined in this paragraph might change in a future
  4838   4842   ** release of SQLite.
................................................................................
  5514   5518   ** commit if the transaction continues to completion.)^
  5515   5519   **
  5516   5520   ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
  5517   5521   ** the opened blob.  ^The size of a blob may not be changed by this
  5518   5522   ** interface.  Use the [UPDATE] SQL command to change the size of a
  5519   5523   ** blob.
  5520   5524   **
         5525  +** ^The [sqlite3_blob_open()] interface will fail for a [WITHOUT ROWID]
         5526  +** table.  Incremental BLOB I/O is not possible on [WITHOUT ROWID] tables.
         5527  +**
  5521   5528   ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
  5522   5529   ** and the built-in [zeroblob] SQL function can be used, if desired,
  5523   5530   ** to create an empty, zero-filled blob in which to read or write using
  5524   5531   ** this interface.
  5525   5532   **
  5526   5533   ** To avoid a resource leak, every open [BLOB handle] should eventually
  5527   5534   ** be released by a call to [sqlite3_blob_close()].

Changes to test/tableopts.test.

    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   do_test tableopt-1.1 {
    21     21     catchsql {
    22     22       CREATE TABLE t1(a,b) WITHOUT rowid;
    23     23     }
    24         -} {1 {no PRIMARY KEY for table t1}}
           24  +} {1 {PRIMARY KEY missing on table t1}}
           25  +do_test tableopt-1.1b {
           26  +  catchsql {
           27  +    CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT,b) WITHOUT rowid;
           28  +  }
           29  +} {1 {AUTOINCREMENT not allowed on WITHOUT ROWID tables}}
    25     30   do_test tableopt-1.2 {
    26     31     catchsql {
    27     32       CREATE TABLE t1(a,b) WITHOUT unknown2;
    28     33     }
    29     34   } {1 {unknown table option: unknown2}}
    30     35   
    31     36   do_execsql_test tableopt-2.1 {