我希望获得当前时间戳记的所有记录。根据[this] [1]我创建查询
SELECT *
FROM table
WHERE timestamp BETWEEN date('now', 'start of day', 'localtime', 'unixepoch') AND
date('now', 'start of day','+1 day', 'localtime', 'unixepoch')"
但总是一无所获。我更新了一些调用System.currentTimeMillis()/1000
函数的记录。我尝试没有unixepoch
参数但仍然没有任何东西
private static final String DATABASE_CREATE = "create table if not exists "
+ TABLE_DAILY_CHALLENGES +
"(" + DAILY_CHALLENGES_ID + " integer primary key autoincrement, " +
DAILY_CHALLENGES_TITLE + " text not null, "+
DAILY_CHALLENGES_CONTENT + " text not null, "+
DAILY_CHALLENGES_COUNTER + " text not null, "+
DAILY_CHALLENGES_SORT+ " integer not null, " +
DAILY_CHALLENGES_ACTUAL_COUNTER+ " text not null, " +
DAILY_CHALLENGES_TIMESTAMP+ " integer DEFAULT 0, " +
DAILY_CHALLENGES_FINISHED+ " integer DEFAULT 0, " +
DAILY_CHALLENGES_TYPE + " text not null);";
private static Database getDbHandlerInstance(){
if(dbHandler==null){
return init();
}else
return dbHandler;
}
private static Database init(){
dbHandler = DatabaseFactory.getNewDatabase(DATABASE_NAME,
DATABASE_VERSION, DATABASE_CREATE, null);
dbHandler.setupDatabase();
try {
dbHandler.openOrCreateDatabase();
dbHandler.execSQL(DATABASE_CREATE);
} catch (SQLiteGdxException e) {
e.printStackTrace();
}
try { //TODO:: make it more efficient
String query="SELECT * FROM dailyChallenges";
DatabaseCursor cursor = dbHandler.rawQuery(query);
if(cursor.getCount()!=NUMBERS_OF_RECORDS){
cleanTable();
populateDatabase();
}
} catch (SQLiteGdxException e) {
e.printStackTrace();
}
return dbHandler;
}
private static void cleanTable() {
try {
dbHandler.execSQL("delete from "+ TABLE_DAILY_CHALLENGES);
} catch (SQLiteGdxException e) {
e.printStackTrace();
}
}
public static Challenge[] getChallenge(){
DatabaseCursor cursor=null,cursorAll=null;
Challenge[] challenge;
try {
String query="SELECT * FROM dailyChallenges WHERE timestamp BETWEEN date('now', 'start of day', 'localtime', 'unixepoch') AND date('now', 'start of day','+1 day', 'localtime', 'unixepoch')";
cursor = getDbHandlerInstance().rawQuery(query);
} catch (SQLiteGdxException e) {
e.printStackTrace();
}
//create new challenge
if(cursor.getCount()!=0){
//logic,cursor.getCount() is always 0}