无法从 android 中的数据库中删除行(where 子句后的 sql 查询为空)
Unable to delete a row from database in android (sql query is empty after the where clause)
由于某种原因,sql 查询未完成,
DELETE FROM activations WHERE smsArrivalTimeStamp =
异常
01-08 16:19:01.447: E/AndroidRuntime(4659): Caused by: android.database.sqlite.SQLiteException: near "=": syntax error (code 1): , while compiling: DELETE FROM activations WHERE smsArrivalTimeStamp =
01-08 16:19:01.447: E/AndroidRuntime(4659): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
代码
public void deleteActivation(long timeStamp) {
String selection = God.COLUMN_NAME_SMS_ARRIVAL_TIME_STAMP + " = ";
String[] selectionArgs = { String.valueOf(timeStamp) };
System.out.println("Selections Args "+ selectionArgs[0]) ;
God.activationsDB.getWritableDatabase().delete(God.TABLE_ACTIVATIONS,
selection, selectionArgs);
}
system.out 正在打印
01-08 16:06:50.887: I/System.out(4295): Selections Args 1420704490320
?(问号符号) 是 selection
语句所必需的
改变这个
String selection = God.COLUMN_NAME_SMS_ARRIVAL_TIME_STAMP + " = ";
进入
String selection = God.COLUMN_NAME_SMS_ARRIVAL_TIME_STAMP + " = ?";
由于某种原因,sql 查询未完成,
DELETE FROM activations WHERE smsArrivalTimeStamp =
异常
01-08 16:19:01.447: E/AndroidRuntime(4659): Caused by: android.database.sqlite.SQLiteException: near "=": syntax error (code 1): , while compiling: DELETE FROM activations WHERE smsArrivalTimeStamp =
01-08 16:19:01.447: E/AndroidRuntime(4659): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
代码
public void deleteActivation(long timeStamp) {
String selection = God.COLUMN_NAME_SMS_ARRIVAL_TIME_STAMP + " = ";
String[] selectionArgs = { String.valueOf(timeStamp) };
System.out.println("Selections Args "+ selectionArgs[0]) ;
God.activationsDB.getWritableDatabase().delete(God.TABLE_ACTIVATIONS,
selection, selectionArgs);
}
system.out 正在打印
01-08 16:06:50.887: I/System.out(4295): Selections Args 1420704490320
?(问号符号) 是 selection
语句所必需的
改变这个
String selection = God.COLUMN_NAME_SMS_ARRIVAL_TIME_STAMP + " = ";
进入
String selection = God.COLUMN_NAME_SMS_ARRIVAL_TIME_STAMP + " = ?";