繁体   English   中英

我如何使用 sqflite 并且只在 flutter 上查询 1 行数据

[英]How do I use sqflite and only query 1 row of data on flutter

我如何使用 sqflite 并且只在 flutter 上查询 1 行数据。

  Future<dynamic> queryOneDaily (int id, String date) async {
    final db = await database;
    return await db.query(
      Constants.dbTable, 
      where: "${Constants.dbColId} = ? AND ${Constants.dbColDate} = ?",
      whereArgs: [id, date],
    );
  }

来自sqlite的源代码
https://github.com/tekartik/sqflite/blob/master/sqflite/lib/sqlite_api.dart

您可以使用limit

代码片段

Future<dynamic> queryOneDaily (int id, String date) async {
    final db = await database;
    return await db.query(
      Constants.dbTable, 
      where: "${Constants.dbColId} = ? AND ${Constants.dbColDate} = ?",
      whereArgs: [id, date],
      limit: 1
    );
  }

源代码的代码片段

/// @param limit Limits the number of rows returned by the query,
Future<List<Map<String, dynamic>>> query(String table,
      {bool distinct,
      List<String> columns,
      String where,
      List<dynamic> whereArgs,
      String groupBy,
      String having,
      String orderBy,
      int limit,
      int offset});

暂无
暂无

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

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