Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Local Storage parameter replacement escaping

Tags:

html

sql

sqlite

I'm experimenting with a simple HTML5 local storage based app and I'm having trouble with the parameter replacement escaping (maybe) in my code.

The SQL line I want to execute is:

SELECT name, title FROM testTable WHERE name LIKE '%test%';

so my Javascript line is something like:

tx.executeSql( "SELECT name, title FROM testTable WHERE name LIKE '%?%'", [ search_string ],

This fails (I think) because the ? is being treated as a literal and so the parser complains about too many parameters (search_string).

I optimistically tried using ??? and ["'%", search_string, "%'"] but same result.

Any suggestions - I imagine it's something really obvious so please be gentle.

like image 819
speedwell Avatar asked Mar 20 '26 22:03

speedwell


1 Answers

How about:

tx.executeSql( 
    "SELECT name, title FROM testTable WHERE name LIKE ?", 
    [ '%'+search_string+'%' ]
    );
like image 100
Ned Batchelder Avatar answered Mar 22 '26 12:03

Ned Batchelder