首页 > 解决方案 > 如何在flutter上查询sqflite多个whereArgs?

问题描述

如何查询多个 whereArgs?我总是返回 1 行。它应该返回 3 行。

final res = await db.query(
  Constants.dbTable, 
  where: "name = ?",
  whereArgs: ['read', "uio", 'go'],  
);

标签: sqlsqliteflutterdartsqflite

解决方案


尝试使用 IN 子句:

final res = await db.query(
  Constants.dbTable, 
  where: "name IN (?, ?, ?)",
  whereArgs: ['read', 'uio', 'go'],  
);

更新!

对于动态List<String> names,您可以尝试使用这种方法:

final res = await db.query(
  Constants.dbTable, 
  where: "name IN (${('?' * (names.length)).split('').join(', ')})",
  whereArgs: names,  
);

推荐阅读