/ Check-in [d75e6765]
Login

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

Overview
Comment:Detect databases whose schema is corrupted using a CREATE TABLE AS statement and issue an appropriate error message.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d75e67654aa9620b9617786553a002f54e8c6dcbbcc58948a06bd98a0916d75a
User & Date: drh 2018-03-16 20:23:01
Context
2018-03-16
23:59
Detect corruption in the form of the sqlite_sequence table pointing to the wrong type of btree. check-in: 525deb7a user: drh tags: trunk
23:53
Fix a duplicate test number and cleanup a bit of Makefile whitespace. check-in: 56d11c25 user: mistachkin tags: testFixes
20:23
Detect databases whose schema is corrupted using a CREATE TABLE AS statement and issue an appropriate error message. check-in: d75e6765 user: drh tags: trunk
20:15
Better error message text when the schema is corrupted by a CREATE TABLE AS entry. Closed-Leaf check-in: e13993cf user: drh tags: corrupt-schema
07:48
Fix a problem in test script thread001.test causing a spurious "-1 files were left open" error when run separately. check-in: 1774f1c3 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

  1866   1866     if( pEnd==0 && pSelect==0 ){
  1867   1867       return;
  1868   1868     }
  1869   1869     assert( !db->mallocFailed );
  1870   1870     p = pParse->pNewTable;
  1871   1871     if( p==0 ) return;
  1872   1872   
  1873         -  assert( !db->init.busy || !pSelect );
  1874         -
  1875   1873     /* If the db->init.busy is 1 it means we are reading the SQL off the
  1876   1874     ** "sqlite_master" or "sqlite_temp_master" table on the disk.
  1877   1875     ** So do not write to the disk again.  Extract the root page number
  1878   1876     ** for the table from the db->init.newTnum field.  (The page number
  1879   1877     ** should have been put there by the sqliteOpenCb routine.)
  1880   1878     **
  1881   1879     ** If the root page number is 1, that means this is the sqlite_master
  1882   1880     ** table itself.  So mark it read-only.
  1883   1881     */
  1884   1882     if( db->init.busy ){
         1883  +    if( pSelect ){
         1884  +      sqlite3ErrorMsg(pParse, "");
         1885  +      return;
         1886  +    }
  1885   1887       p->tnum = db->init.newTnum;
  1886   1888       if( p->tnum==1 ) p->tabFlags |= TF_Readonly;
  1887   1889     }
  1888   1890   
  1889   1891     /* Special processing for WITHOUT ROWID Tables */
  1890   1892     if( tabOpts & TF_WithoutRowid ){
  1891   1893       if( (p->tabFlags & TF_Autoincrement) ){

Changes to src/prepare.c.

    25     25     const char *zExtra   /* Error information */
    26     26   ){
    27     27     sqlite3 *db = pData->db;
    28     28     if( !db->mallocFailed && (db->flags & SQLITE_WriteSchema)==0 ){
    29     29       char *z;
    30     30       if( zObj==0 ) zObj = "?";
    31     31       z = sqlite3MPrintf(db, "malformed database schema (%s)", zObj);
    32         -    if( zExtra ) z = sqlite3MPrintf(db, "%z - %s", z, zExtra);
           32  +    if( zExtra && zExtra[0] ) z = sqlite3MPrintf(db, "%z - %s", z, zExtra);
    33     33       sqlite3DbFree(db, *pData->pzErrMsg);
    34     34       *pData->pzErrMsg = z;
    35     35     }
    36     36     pData->rc = db->mallocFailed ? SQLITE_NOMEM_BKPT : SQLITE_CORRUPT_BKPT;
    37     37   }
    38     38   
    39     39   /*