【发布时间】:2013-01-23 00:48:17
【问题描述】:
我的数据库中有下表:
database.execSQL("create table " + TABLE_LOGS + " ("
+ COLUMN_ID + " integer primary key autoincrement,"
+ COLUMN_ID_DAY_EXERCISE + " integer not null,"
+ COLUMN_REPS + " integer not null,"
+ COLUMN_WEIGHT + " real not null,"
+ COLUMN_1RM + " real not null,"
+ COLUMN_DATE + " integer not null"
+ ")");
我在 COLUMN_DATE 字段(整数)中存储了一个 unix 时间戳。
现在我有以下函数可以抓取所有记录:
public Cursor fetchCurrentLogs(long dayExerciseDataID) {
// where day = today
Cursor cursor = database.rawQuery("select " + MySQLiteHelper.COLUMN_ID + "," + MySQLiteHelper.COLUMN_REPS + ", " + MySQLiteHelper.COLUMN_WEIGHT + " " +
"from " + MySQLiteHelper.TABLE_LOGS + " " +
"where " + MySQLiteHelper.COLUMN_ID_DAY_EXERCISE + " = '" + dayExerciseDataID + "'", null);
if (cursor != null) { cursor.moveToFirst(); }
return cursor;
}
现在我想做的是,我想让这个函数只抓取今天的记录。
然后我想使另一个功能完全相同,但是我希望它获取前一天的记录,而不是获取今天的记录。以前,我的意思是最近一天的记录不是今天。所以可能是昨天,也可能是 3 天前,也可能是一个月前。
我知道在 MySQL 中你可以在当天做这样的事情:
where date_format(from_unixtime(COLUMN_DATE), '%Y-%m-%d')= date_format(now(), '%Y-%m-%d')
SQLite 的等价物是什么?
另外,有人可以帮我解决上面提到的前一天的 where 子句吗?
非常感谢。
【问题讨论】:
-
COLUMN_DATE 的值是多少?是在 unix 时间戳中吗?
标签: android sqlite date select