如何解决如何使用通过Kotlin传递的相同参数对IN子句使用多个值
为什么IN子句/运算符无法从表中检索type1,type2行?
这写在main.kt文件中
//if i write here **var type="type1"** then the DAO fetches correct result
but i want to fetch both type1 and type2. So,I am writing it in following way
and then passing the "type" variable as "bind variable" in DAO
but nothing is fetched and the output is blank//
var type="'type1','type2'"
var sq = runBlocking {qdatabase(applicationContext).getquizdao().engquest(type).shuffled()}
这是用DAO编写的
@Query("SELECT * FROM tabledata WHERE Subject='English' AND Qtype IN(:types)")
suspend fun engquest(types:String):List<quizdata>
这是数据库。
Question|Subject| Qtype |
------ |-------|------ |
Quest1 |English| type1 |
Quest2 |English| type2 |
Quest3 |English| type3 |
解决方法
您必须传递数组或类型列表:
var type = listOf("type1","type2")
var sq = runBlocking {qdatabase(applicationContext).getquizdao().engquest(type).shuffled()}
@Query("SELECT * FROM tabledata WHERE Subject='English' AND Qtype IN(:types)")
suspend fun engquest(types:List<String>):List<quizdata>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。