SQLite

Check-in [e3c8935f87]
Login

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

Overview
Comment:Fix the CREATE INDEX statement so that trying to create a TEMP index on a non-TEMP table throws an error rather than segfaulting.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e3c8935f8736d00dc83644fa21d86ca7fec6d2fc
User & Date: drh 2013-08-01 22:27:26.044
Context
2013-08-02
13:31
Fix typos in documentation for SQLITE_DBSTATUS_DEFERRED_FKS . No changes to code. (check-in: f3efbfcd51 user: drh tags: trunk)
2013-08-01
22:27
Fix the CREATE INDEX statement so that trying to create a TEMP index on a non-TEMP table throws an error rather than segfaulting. (check-in: e3c8935f87 user: drh tags: trunk)
22:26
Fix an incorrect expected result in a test case in corruptG.test. (check-in: 6913831ad2 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/build.c.
2546
2547
2548
2549
2550
2551
2552
2553





2554
2555
2556
2557
2558
2559
2560
      /* Because the parser constructs pTblName from a single identifier,
      ** sqlite3FixSrcList can never fail. */
      assert(0);
    }
    pTab = sqlite3LocateTableItem(pParse, 0, &pTblName->a[0]);
    assert( db->mallocFailed==0 || pTab==0 );
    if( pTab==0 ) goto exit_create_index;
    assert( db->aDb[iDb].pSchema==pTab->pSchema );





  }else{
    assert( pName==0 );
    assert( pStart==0 );
    pTab = pParse->pNewTable;
    if( !pTab ) goto exit_create_index;
    iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
  }







|
>
>
>
>
>







2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
      /* Because the parser constructs pTblName from a single identifier,
      ** sqlite3FixSrcList can never fail. */
      assert(0);
    }
    pTab = sqlite3LocateTableItem(pParse, 0, &pTblName->a[0]);
    assert( db->mallocFailed==0 || pTab==0 );
    if( pTab==0 ) goto exit_create_index;
    if( iDb==1 && db->aDb[iDb].pSchema!=pTab->pSchema ){
      sqlite3ErrorMsg(pParse, 
           "cannot create a TEMP index on non-TEMP table \"%s\"",
           pTab->zName);
      goto exit_create_index;
    }
  }else{
    assert( pName==0 );
    assert( pStart==0 );
    pTab = pParse->pNewTable;
    if( !pTab ) goto exit_create_index;
    iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
  }
Changes to test/index.test.
711
712
713
714
715
716
717

















718
719
720
  }
} {}
do_test index-20.2 {
  execsql {
    DROP INDEX "t6i1";
  }
} {}

















   

finish_test







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
  }
} {}
do_test index-20.2 {
  execsql {
    DROP INDEX "t6i1";
  }
} {}

# Try to create a TEMP index on a non-TEMP table. */
#
do_test index-21.1 {
  catchsql {
     CREATE INDEX temp.i21 ON t6(c);
  }
} {1 {cannot create a TEMP index on non-TEMP table "t6"}}
do_test index-21.2 {
  catchsql {
     CREATE TEMP TABLE t6(x);
     INSERT INTO temp.t6 values(1),(5),(9);
     CREATE INDEX temp.i21 ON t6(x);
     SELECT x FROM t6 ORDER BY x DESC;
  }
} {0 {9 5 1}}

   

finish_test