1

I have a DAO method like this:

@Query("SELECT * FROM Libs where :field like :search")
fun findLib(search:String,field:String): List<Lib>

I want to replace field as is, but Room adds quotation marks to it in generated code. For example I want to findLib("james%","author") to generate this SQL:

SELECT * FROM Libs where author like "james%"

but it generates this :

SELECT * FROM Libs where "author" like "james%" 

how can I force it to not embed in quote marks?

AVEbrahimi
  • 17,993
  • 23
  • 107
  • 210

1 Answers1

1

SQLite does not support parameters for column names as far as I know. Thus you are misusing Room. Correct use case would be this:

@Query("SELECT * FROM Libs WHERE author LIKE :search")
fun findLib(search:String): List<Lib>

Usage: findLib("james%")

ror
  • 3,295
  • 1
  • 19
  • 27