我无法在sqflite中按日期范围查询。created_at日期保存为IsoString,start
和end
的格式为yyyy-mm-dd
。查询如下
await db!.rawQuery('''SELECT $mealTable.id as meal_id,
$mealTable.meal_name, $ordersTable.*
FROM $ordersTable
WHERE $orderCreatedAt >= '$start' AND $orderCreatedAt < '$end'
LEFT JOIN $mealTable ON $mealTable.id = $ordersTable.order_meal'''
);
这是我得到的错误
I/flutter (20062): ======error happened: DatabaseException(near "LEFT": syntax error (code 1 SQLITE_ERROR): , while compiling: SELECT meal_table.id as meal_id,
I/flutter (20062): meal_table.meal_name, orders_table.*
I/flutter (20062): FROM orders_table
I/flutter (20062): WHERE created_at >= '2023-03-27' AND created_at < '2023-03-28'
I/flutter (20062): LEFT JOIN meal_table ON meal_table.id = orders_table.order_meal) sql 'SELECT meal_table.id as meal_id,
I/flutter (20062): meal_table.meal_name, orders_table.*
I/flutter (20062): FROM orders_table
I/flutter (20062): WHERE created_at >= '2023-03-27' AND created_at < '2023-03-28'
I/flutter (20062): LEFT JOIN meal_table ON meal_table.id = orders_table.order_meal' args []====
在我发疯之前,有人能发现错误吗?
1条答案
按热度按时间tpgth1q71#
您应该像这样编写rawquery
你应该把所有变量都写在方括号里。