我只是好奇,date
是SQLite
的保留字吗?我有一个名为date的列,并尝试运行此查询:
DELETE FROM cases WHERE date <= date('now','-1 day')
通过这样做:
String query = "DELETE FROM cases WHERE date <= date('now','-1 day')";
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(query, null);
boolean found = cursor.moveToFirst();
if(found) {
int result = cursor.getCount();
Log.w("DeleteOldCases: ", "Result: " + Integer.toString(result));
db.close();
}
但是当调用moveToFirst
时,光标只会给我一个错误的回复。但是在我的数据库中,实际上存在超过一天的行。任何人都可以解释这里有什么问题吗?
谢谢!
答案 0 :(得分:0)
是的,这似乎是一个保守的词。
看看:http://www.sqlite.org/lang_datefunc.html
date(timestring, modifier, modifier, ...)
有一个游标形成DELETE语句很奇怪。尝试在
中拆分操作SELECT * FROM cases WHERE date <= date('now','-1 day')
然后执行检查
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(query, null);
boolean found = cursor.moveToFirst();
if(found) {
int result = cursor.getCount();
Log.w("DeleteOldCases: ", "Result: " + Integer.toString(result));
db.close();
}
然后执行DELETE部分
DELETE FROM cases WHERE date <= date('now','-1 day')