[我想通过提供一些条件,例如在ID = x的情况下返回所有不同的记录,来返回SQLITE flutter中的表的不同记录,其中ID = x(其中x将由用户使用)。
我该如何实现?
使用SQFlite package,您可以使用query
或rawQuery
来执行此操作,在两种情况下,您都需要将where arguments
作为array
传递,对于distinct operator
,您可以它如下:
/// [GET] Get all the data by date using a query
getData(String date) async {
final db = await database;
final response = await db.query(
"TableExample",
distinct: true,
orderBy: 'id',
where: 'date = ?',
whereArgs: [date],
);
//...
}
/// [GET] Get all the data by date using a rawQuery
getDailyPollResponsesPerRangeDate(String date) async {
final db = await database;
final response = await db.rawQuery(
"SELECT DISTINCT TableExample.id, TableExample.date "
"FROM TableExample "
"WHERE TableExample.date == ? "
"ORDER BY TableExample.date DESC",
[date],
);
//...
}