2011-02-12 122 views
0

我正在嘗試爲我的android應用程序實現數據庫升級。我嘗試使用以下代碼:升級SQLite數據庫時出錯

// Create a table that is equivalent to the existing one but with one column as TEXT instead of INTEGER 
db.execSQL("CREATE VIRTUAL TABLE distributors_new USING FTS3 (fname TEXT, lname TEXT, phoneNumber TEXT, email TEXT, notes TEXT, parentid INTEGER, customid TEXT FOREIGN KEY (parentid) REFERENCES distributors(rowid) ON DELETE CASCADE ON UPDATE CASCADE);"); 
//Insert all data from the old table to the new one. 
db.execSQL("INSERT INTO distributors_new SELECT * FROM distributors;"); 
// Drop the old table 
db.execSQL("DROP TABLE distributors;"); 
// Rename the new table 
db.execSQL("ALTER TABLE distributors_new RENAME TO distributors;"); 

但是,我在執行onUpgrade方法後出現錯誤。

02-12 16:31:16.324: ERROR/Database(1456): Failure 1 (SQL logic error or missing database) on 0x26b338 when executing 'COMMIT;' 
02-12 16:31:16.334: ERROR/SQLiteOpenHelper(1456): Couldn't open mlmDB for writing (will try read-only): 
02-12 16:31:16.334: ERROR/SQLiteOpenHelper(1456): android.database.sqlite.SQLiteException: SQL logic error or missing database: COMMIT; 
02-12 16:31:16.334: ERROR/SQLiteOpenHelper(1456) 

我在做什麼錯?

回答

1

有,AFAIK,沒有理由這樣做。 Sqlite使用dynamic typing,所以創建表時的數據類型沒有什麼重要性。它隻影響類型親和力,請檢查鏈接的文檔。

1

我並不是SQL專家,但是在我看來,您並未連接到數據庫服務器,或者您沒有您認爲的特權級別。

+0

沒有服務器。它是一個android設備上的sqlite數據庫。 – 2011-02-12 14:52:58

1

我加

db.beginTransaction(); 
// Code 
db.endTransaction(); 

而現在它似乎工作。

+0

hm - 實際上這個方法無論如何都被封裝在一個事務中 – Dori 2013-03-13 17:11:19