我有这样的DAO方法:
@Query("SELECT * FROM Libs where :field like :search")
fun findLib(search:String,field:String): List<Lib>
我想原样替换 field ,但Room在生成的代码中为其添加了引号。 例如,我想要findLib(“ james%”,“ author”)生成此SQL:
SELECT * FROM Libs where author like "james%"
但它会生成此内容:
SELECT * FROM Libs where "author" like "james%"
如何强制它不插入引号?
答案 0 :(得分:1)
SQLite不支持列名的参数。因此,您正在滥用房间。正确的用例是这样:
@Query("SELECT * FROM Libs WHERE author LIKE :search")
fun findLib(search:String): List<Lib>
用法:findLib(“ james%”)