Index: src/build.c ================================================================== --- src/build.c +++ src/build.c @@ -20,11 +20,11 @@ ** creating ID lists ** BEGIN TRANSACTION ** COMMIT ** ROLLBACK ** -** $Id: build.c,v 1.413 2007/02/02 12:44:37 drh Exp $ +** $Id: build.c,v 1.414 2007/03/13 16:32:25 danielk1977 Exp $ */ #include "sqliteInt.h" #include /* @@ -2355,21 +2355,21 @@ if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){ goto exit_create_index; } if( !db->init.busy ){ if( SQLITE_OK!=sqlite3ReadSchema(pParse) ) goto exit_create_index; + if( sqlite3FindTable(db, zName, 0)!=0 ){ + sqlite3ErrorMsg(pParse, "there is already a table named %s", zName); + goto exit_create_index; + } + } if( sqlite3FindIndex(db, zName, pDb->zName)!=0 ){ if( !ifNotExist ){ sqlite3ErrorMsg(pParse, "index %s already exists", zName); } goto exit_create_index; } - if( sqlite3FindTable(db, zName, 0)!=0 ){ - sqlite3ErrorMsg(pParse, "there is already a table named %s", zName); - goto exit_create_index; - } - } }else{ char zBuf[30]; int n; Index *pLoop; for(pLoop=pTab->pIndex, n=1; pLoop; pLoop=pLoop->pNext, n++){} Index: test/corrupt2.test ================================================================== --- test/corrupt2.test +++ test/corrupt2.test @@ -11,11 +11,11 @@ # This file implements regression tests for SQLite library. # # This file implements tests to make sure SQLite does not crash or # segfault if it sees a corrupt database file. # -# $Id: corrupt2.test,v 1.3 2007/02/14 12:32:13 drh Exp $ +# $Id: corrupt2.test,v 1.4 2007/03/13 16:32:25 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # The following tests - corrupt2-1.* - create some databases corrupted in @@ -101,8 +101,35 @@ sqlite3 db2 corrupt.db catchsql { SELECT * FROM sqlite_master; } db2 } {1 {database disk image is malformed}} +db2 close + +# Corrupt a database by having 2 indices of the same name: +do_test corrupt2-2.1 { + + file delete -force corrupt.db + file delete -force corrupt.db-journal + copy_file test.db corrupt.db + + sqlite3 db2 corrupt.db + execsql { + CREATE INDEX a1 ON abc(a); + CREATE INDEX a2 ON abc(b); + PRAGMA writable_schema = 1; + UPDATE sqlite_master + SET name = 'a3', sql = 'CREATE INDEX a3' || substr(sql, 16, 10000) + WHERE type = 'index'; + PRAGMA writable_schema = 0; + } db2 + + db2 close + sqlite3 db2 corrupt.db + catchsql { + SELECT * FROM sqlite_master; + } db2 +} {1 {malformed database schema - index a3 already exists}} + db2 close finish_test