当我尝试向 sqlite 数据库添加多行时发生错误。单排没有问题。此外,该应用程序因此在三星 Galaxy s2 上崩溃,但不是在 nexus 上。
下面是创建表的代码:
private static final String DATABASE_CREATE = "create table "
+ TABLE_AWARDS + "(" + COLUMN_ID
+ " integer primary key autoincrement, " + COLUMN_TITLE
+ " text not null, " + COLUMN_DESCRIPTION + " text not null, "
+ COLUMN_TYPE + " integer not null, " + COLUMN_ACHIEVED
+ " integer not null " + ");";
以及将行插入表中的代码:
private static final String DATABASE_INSERT = "INSERT into awards (title, description, type, achieved) VALUES "
+ "('Speed maximum', 'Stay', 1 , 0),"
+ "('Speed maximum', 'under 130 km/h', 2 , 0);";
根据你给我的stackoverflow问题的答案,语法应该是:
private static final String DATABASE_INSERT = "INSERT into 'awards' "+
"SELECT 'Speed maximum' AS 'title', 'under 150 km/h' AS 'description', 1 AS 'type', 0 AS 'achieved'"
+" UNION SELECT 'Speed maximum', 'under 130 km/h', 2 , 0"
+" UNION SELECT 'Speed maximum', 'under 100 km/h', 3 , 0";
但这也不起作用。