Search code examples
sqliteweb-sql

WebDB - SQLLite LIKE syntax...escaping me


Trying these:

tx.executeSql("SELECT * FROM Animal_Traits WHERE animalName LIKE %?% OR trait LIKE %?% ORDER BY animalName", [searchValue, searchValue],

with THIS one, I am told that the syntax breaks on the % symbol...so if I try THIS:

tx.executeSql("SELECT * FROM Animal_Traits WHERE animalName LIKE '%'?'%' OR trait LIKE '%'?'%' ORDER BY animalName", [searchValue, searchValue],

and it tells me the syntax breaks on the ? symbol... (guess the first one?) AND IF I TRY THIS:

tx.executeSql("SELECT * FROM Animal_Traits WHERE animalName LIKE '%?%' OR trait LIKE '%?%' ORDER BY animalName", [searchValue, searchValue],

It tells me that the number of arguments do not match... grrr!

Can someone help me please.

thanks!


Solution

  • You need to do this:

    ... WHERE animalName LIKE '%' || ? || '%' OR trait LIKE '%' || ? || '%'
    

    The || is a string concatenator. And the question mark should be outside of the quotes.