How to use named parameters inside LIKE operator pattern in Adobe Air

adobe, air, database, sqlite

Solution

Found a solution for this, basically instead of doing it like this:

var stmt = new air.SQLStatement();
stmt.text = "SELECT * FROM comments WHERE title LIKE '%@search%';";
stmt.parameters["@search"] = "argument string";
stmt.execute();

You have to put a placeholder for the entire LIKE operator pattern and bind the pattern as a parameter.

var stmt = new air.SQLStatement();
stmt.text = "SELECT * FROM comments WHERE title LIKE @search;";
stmt.parameters["@search"] = "%" + userInput + "%";
stmt.execute();

Problem

I wanted to use a named parameter placeholder inside the LIKE operator pattern so that the argument string is properly escaped. Here's my modified code where I am using the at-param placeholder: var stmt = new air.SQLStatement(); stmt.text = "SELECT * FROM comments WHERE title LIKE '%@search%';"; stmt.parameters["@search"] = "argument string"; stmt.execute(); Doing so yields an SQLError with the following details message: Error #3315: SQL Error. details: '@search' parameter name(s) found in parameters property but not in the SQL specified As suggested by Mike Petty, I tried: stmt.text = 'SELECT * FROM comments WHERE title LIKE "@%search%";'; Which yields to the same SQL Error details. Documentation has this: expr ::= (column-name | expr) LIKE pattern pattern ::= '[ string | % | _ ]' My suspicion is that it is skipped due to the qoutes, any ideas on how to make it work?

Original source