flutter 无法在sqflite中按日期范围查询

ewm0tg9j  于 2023-04-13  发布在  Flutter
关注(0)|答案(1)|浏览(132)

我无法在sqflite中按日期范围查询。created_at日期保存为IsoString,startend的格式为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 []====

在我发疯之前,有人能发现错误吗?

tpgth1q7

tpgth1q71#

您应该像这样编写rawquery

somedb.rawQuery("SELECT * FROM SomeTable WHERE SomeColumn = ?",["$element"])

你应该把所有变量都写在方括号里。

相关问题