表"凭据"确实显示在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);";
Run Code Online (Sandbox Code Playgroud)
我一直在倾倒这个,我打赌它有些愚蠢的语法错字!或者,至少我希望这是微不足道的;-)
Sep*_*phy 11
我想你正在使用:
yourDB.execSQL("your statement");
Run Code Online (Sandbox Code Playgroud)
如果是这样,谷歌文档提到:
执行不是查询的单个SQL语句.例如,CREATE TABLE,DELETE,INSERT等.不支持由; s分隔的多个语句.它需要一个写锁定
因此,您必须对每个create table语句进行分段,并对每个表重复查询.
如果我没记错的话,我遇到了类似的问题,并发现每次调用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);
Run Code Online (Sandbox Code Playgroud)
Pra*_*ana -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;";
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5264 次 |
| 最近记录: |