表“凭据”确实显示在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);";
我一直在倾倒这个,我打赌它有些愚蠢的语法拼写!或者,至少我希望它是微不足道的; - )
答案 0 :(得分:11)
我想您正在使用:
yourDB.execSQL("your statement");
如果是这样,谷歌文档提到了这一点:
执行一个SQL语句 不是查询。例如,CREATE TABLE,DELETE,INSERT等多个 由; s分隔的语句不是 支持的。需要写锁定
因此,您必须对每个create table语句进行分段,并对每个表重复查询。
答案 1 :(得分:5)
如果我没记错的话,我遇到了类似的问题,发现每次调用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);
答案 2 :(得分:-3)
在每个Create Table语句之后输入 Go
更新了脚本
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;";