I have a dictionary app where user needs to input in an editText and click the translate button to display the result. It works perfectly but whenever a user inputs a query including ‘ (e.g. Baker’s), I get SQLite error as follows:
android.database.sqlite.SQLiteException: near "s": syntax error (code 1 SQLITE_ERROR[1]): , while compiling: select * from words where vocab = ‘Baker’s’
binding.transcribe.setOnClickListener {
val Word = binding.editText.text.toString()
val Answer = dbHelp.getAnswer(Word)
binding.transcribedVersion.text = Answer
}
How can I fix this problem?
2
Answers
you can use double quote instead of single quote, like this:
select * from words where vocab = 'Baker''s'
Use selection args:
that you can bind later using your value
update
If you are using
rawQuery
it would be like