2010-05-28 49 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