startTime和endTime是格式为“2011-07-22 13:00:00”的字符串。 以下代码使myCursor.moveToFirst()返回false。
String sqlQuery = "SELECT * FROM myData WHERE
strftime('%Y-%m-%d %H:%M:%S', datetime) >= strftime('%Y-%m-%d %H:%M:%S', '"+startTime+"')
AND strftime('%Y-%m-%d %H:%M:%S', datetime) <= strftime('%Y-%m-%d %H:%M:%S', '"+endTime+"')";
Cursor myCursor = myDataBase.rawQuery(sqlQuery, null);
但是,当我进入sqlite3 shell并输入
时SELECT * FROM myData WHERE
strftime('%Y-%m-%d %H:%M:%S', datetime) >= strftime('%Y-%m-%d %H:%M:%S', '2011-07-22 13:00:00')
AND strftime('%Y-%m-%d %H:%M:%S', datetime) <= strftime('%Y-%m-%d %H:%M:%S', '2011-07-22 13:02:00');
它打印出我需要的东西。怎么了?
答案 0 :(得分:0)
您是否错过了moveToFirst()
来电?
String sqlQuery = "SELECT * FROM myData WHERE
strftime('%Y-%m-%d %H:%M:%S', datetime) >= strftime('%Y-%m-%d %H:%M:%S', '"+startTime+"')
AND strftime('%Y-%m-%d %H:%M:%S', datetime) <= strftime('%Y-%m-%d %H:%M:%S', '"+endTime+"')";
Cursor myCursor = myDataBase.rawQuery(sqlQuery, null);
myCursor.moveToFirst(); //