在阅读SQLiteDatabase.execSQL的文档时,我有点意外。它表示“不支持以分号分隔的多个语句。”
我在阅读它之前不会感到惊讶,但我的应用程序使用了如下命令:
private static final String CREATE_TABLE =
"create table "
+ TABLENAME + "("
+ COLUMN_ID + " integer primary key autoincrement, "
+ COLUMN_CODE + " text not null,"
+ COLUMN_NAME + " text not null,"
+ COLUMN_STOCK + " integer,"
+ COLUMN_PRICE + " real,"
+ COLUMN_LISTPRICE + " real"
+ ");"
+ "create index "
+ TABLENAME + "_idx on " + TABLENAME
+ "(" + COLUMN_NAME + ", "
+ COLUMN_STOCK + ", "
+ COLUMN_PRICE
+ ");";
...
database.execSQL(CREATE_TABLE);
我没有发现任何错误或异常(或者我没有注意到)。这是否意味着我的声明中的索引没有创建?或者说文档错了吗?
答案 0 :(得分:-2)
检查字符串之间的串联,并确保在字符串变量之间留一个空格。例如“CREATE TABLE”+ TABLE_NAME“(”+ COLUMN_NAME“INTEGER”+ COLUMN_NAME +“TEXT)”