我有一个名为Order的表,包含3列(id,date,price)。我正在尝试检索date >= startdate AND date <= endDate
的所有数据。 date
列中的日期格式保存为TEXT
:"MM-dd-yyyy HH:mm:ss"
(10-27-2013 12:12:43
)
我尝试了以下SQL语句:
Cursor cursor = cr.query(PizzeriaContentProvider.CONTENT_URI_ORDER, null, PizzeriaDatabase.CELL_ORDER_DATE + " >= DATETIME ("+ startDate + ") AND " +
PizzeriaDatabase.CELL_ORDER_DATE + " <= DATETIME(" + endDate + ")", null, null);
Cursor cursor = cr.query(PizzeriaContentProvider.CONTENT_URI_ORDER, null, PizzeriaDatabase.CELL_ORDER_DATE + " between ( " + startDate + " AND " + endDate + ")", null, null);
但是他们都抛出了同样的例外:
java.lang.RuntimeException: Unable to start activity ComponentInfo{cz.vongrad.pizzeria/presentationLayer.ViewOrder}:
android.database.sqlite.SQLiteException: near "14": syntax error: ,
while compiling: SELECT * FROM orders WHERE (date >= DATETIME(10-27-2013 14:01:53) AND date <= DATETIME(10-27-2013 14:01:53))
所以我想我用错误的格式比较日期?
答案 0 :(得分:1)
失踪的COMMA缺失::
Cursor cursor = cr.query(PizzeriaContentProvider.CONTENT_URI_ORDER, null, PizzeriaDatabase.CELL_ORDER_DATE + " >= DATETIME ('"+ startDate + "') AND " +
PizzeriaDatabase.CELL_ORDER_DATE + " <= DATETIME('" + endDate + "')", null, null);