5

How do I use sqflite and only query 1 row of data on flutter.

  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],
    );
  }
phongyewtong
  • 5,085
  • 13
  • 56
  • 81

1 Answers1

7

From source code of sqlite
https://github.com/tekartik/sqflite/blob/master/sqflite/lib/sqlite_api.dart

You can use limit

code snippet

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
    );
  }

code snippet of source code

/// @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});
chunhunghan
  • 51,087
  • 5
  • 102
  • 120