英文:
How to use multiple values for IN clause using same parameter passed through kotlin
问题
为什么IN子句/操作符无法从表中检索type1、type2行?
这段代码写在main.kt文件中
//如果我在这里写 **var type="type1"**,那么DAO会检索到正确的结果
但是我想要同时检索type1和type2。所以,我以以下方式编写代码
然后将变量"type"作为"绑定变量"传递给DAO
但是没有任何内容被检索出来,输出是空白的//
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 |
英文:
Why the IN clause/operator is unable to retrieve type1,type2 rows from the table?
this is written in main.kt file
//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()}
this is written in DAO
@Query("SELECT * FROM tabledata WHERE Subject='English' AND Qtype IN(:types)")
suspend fun engquest(types:String):List<quizdata>
This is the db.
Question|Subject| Qtype |
------ |-------|------ |
Quest1 |English| type1 |
Quest2 |English| type2 |
Quest3 |English| type3 |
答案1
得分: 2
你必须传递类型的数组或列表:
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>
英文:
You have to pass array or list of types:
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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论