简体   繁体   English

Flutter - 两个日期之间的时间段的 SQFlite 查询不返回数据

[英]Flutter - SQFlite query of period between two dates does not return data

I'm performing a database query from a Flutter application in which I need to bring records in the period between two dates.我正在从 Flutter 应用程序执行数据库查询,我需要在其中带来两个日期之间的记录。 However, the query does not return records even though there are records saved for this period.但是,即使在此期间保存了记录,查询也不会返回记录。

The query below returns zero records:下面的查询返回零记录:

     final List<Map<String, dynamic>> records = await db.rawQuery(
     'SELECT * FROM vehicles WHERE created BETWEEN 2022-07-17 AND 2022-08-16');

Attempting not to use the BETWEEN clause as below did not work either尝试不使用如下 BETWEEN 子句也不起作用

     final List<Map<String, dynamic>> records = await db.rawQuery(
     'SELECT * FROM vehicles WHERE created >= 2022-07-17 AND created <= 2022-08-16');

I also emphasize that the "created" column of the "vehicles" table stores String dates in the following format: YYYY-MM-DD and that the console does not report any syntax errors, it just does not working我还强调“车辆”表的“已创建”列以以下格式存储字符串日期:YYYY-MM-DD,并且控制台不会报告任何语法错误,它只是不起作用

I guess the problem is that you haven't added quotes in date.我想问题是您没有在日期中添加引号。 So it should look like this:所以它应该是这样的:

final List<Map<String, dynamic>> records = await db.rawQuery(
     "SELECT * FROM vehicles WHERE created BETWEEN '2022-07-17' AND '2022-08-16'");

or like this:或像这样:

final List<Map<String, dynamic>> records = await db.rawQuery(
     "SELECT * FROM vehicles WHERE created >= '2022-07-17' AND created <= '2022-08-16'");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM