2010-05-28 118 views
3

表「credentials」在adb shell中顯示。我檢查logcat的,它似乎並沒有報告問題...創建表語句時僅創建第一個表

private static final String DATABASE_CREATE = 
     "create table credentials (_id integer primary key autoincrement, " 
       + "username text not null, password text not null, " 
       + "lastupdate text);" 
     + "create table user (_id integer primary key autoincrement, " 
       + "firstname text not null, " 
       + "lastname text not null);" 
     + "create table phone (_phoneid integer primary key autoincrement, " 
       + "userid integer not null, phonetype text not null, " 
       + "phonenumber text not null);" 
     + "create table email (_emailid integer primary key autoincrement, " 
       + "userid integer not null, emailtype text not null, " 
       + "emailaddress text not null);" 
     + "create table address (_addressid integer primary key autoincrement," 
       + "userid integer not null, addresstype text not null, " 
       + "address text not null);" 
     + "create table instantmessaging (_imid integer primary key autoincrement, " 
       + "userid integer not null, imtype text not null, " 
       + "imaccount text not null);"; 

我已經澆過這一點,我敢打賭,它的一些愚蠢的語法拼寫錯誤!或者,至少我希望是一些小事;-)

回答

-1

轉到每個CREATE TABLE語句

更新腳本

private static final String DATABASE_CREATE = 
     "create table credentials (_id integer primary key autoincrement, " 
       + "username text not null, password text not null, " 
       + "lastupdate text); Go;" 
     + "create table user (_id integer primary key autoincrement, " 
       + "firstname text not null, " 
       + "lastname text not null); Go;" 
     + "create table phone (_phoneid integer primary key autoincrement, " 
       + "userid integer not null, phonetype text not null, " 
       + "phonenumber text not null); Go;" 
     + "create table email (_emailid integer primary key autoincrement, " 
       + "userid integer not null, emailtype text not null, " 
       + "emailaddress text not null) Go;;" 
     + "create table address (_addressid integer primary key autoincrement," 
       + "userid integer not null, addresstype text not null, " 
       + "address text not null); Go;" 
     + "create table instantmessaging (_imid integer primary key autoincrement, " 
       + "userid integer not null, imtype text not null, " 
       + "imaccount text not null); Go;"; 
+0

嗯,剛剛嘗試過,仍然沒有運氣... – Craig 2010-05-28 10:29:52

+0

比嘗試打破每個語句比執行和看到的結果,因爲可能是由於聲明 – 2010-05-28 10:36:16

4

如果我沒有記錯後,我遇到了類似的問題,發現每次調用execSQL()或類似方法時只執行1個語句。任何額外的陳述都會被忽略。

嘗試將每個語句分隔爲單獨的字符串並分別執行它們,而不是單個字符串和單個調用。

例如:

private static final String TABLE_1 = 
    "create table credentials (_id integer primary key autoincrement, " 
    + "username text not null, password text not null, " 
    + "lastupdate text);"; 

private static final String TABLE_2 = 
    "create table user (_id integer primary key autoincrement, " 
    + "firstname text not null, " 
    + "lastname text not null);"; 

private static final String TABLE_3 = 
    "create table phone (_phoneid integer primary key autoincrement, " 
    + "userid integer not null, phonetype text not null, " 
    + "phonenumber text not null);"; 

private static final String TABLE_4 = 
    "create table email (_emailid integer primary key autoincrement, " 
    + "userid integer not null, emailtype text not null, " 
    + "emailaddress text not null);"; 

private static final String TABLE_5 = 
    "create table address (_addressid integer primary key autoincrement," 
    + "userid integer not null, addresstype text not null, " 
    + "address text not null);"; 

private static final String TABLE_6 = 
    "create table instantmessaging (_imid integer primary key autoincrement, " 
    + "userid integer not null, imtype text not null, " 
    + "imaccount text not null);"; 

public void createTables(){ 
    db.execSQL(TABLE_1); 
    db.execSQL(TABLE_2); 
    db.execSQL(TABLE_3); 
    db.execSQL(TABLE_4); 
    db.execSQL(TABLE_5); 
} 
db.execSQL(TABLE_6); 
7

我假設你正在使用:

yourDB.execSQL("your statement"); 

如果是這樣,谷歌文檔中提到這一點:

執行一個SQL語句是 不是查詢。例如,CREATE TABLE,DELETE,INSERT等。多個支持的 由...分隔的語句不是 。它需要一個寫鎖

因此,你必須將每個創建表語句分段並對每個表重複查詢。

+0

之一的異常原因而不允許分號 – 2010-05-28 12:02:53