繁体   English   中英

如何在flutter上查询sqflite多个whereArgs?

[英]how to query sqflite multiple whereArgs on flutter?

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

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

尝试使用 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,  
);

我通过创建动态解决了它? 到哪里。

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

你可以这样查询:

var names = ['read', "uio", 'go'];
final res = await db.query(
  Constants.dbTable, 
  where: "name IN (${names.join(',')})",
);

whereArgs 是一个可选参数。 如果您觉得通过使用 whereArgs 来制定您的 where-clause 很麻烦,您可以通过您自己的代码制作人口。 在这个例子中,自己填充 IN 列表更容易。

使用逗号“,”

例如:UPDATE my_table SET rowOneValue = rowOneValue + 1, rowTwoValue = rowTwoValue + ( (rowTwoValue / (rowTwoValue) ) + ?) * (v + 1) WHERE value = ?

暂无
暂无

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

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