Cordova-sqlite-storage: Select query with a condition "LIKE"

Created on 23 Mar 2015  路  1Comment  路  Source: storesafe/cordova-sqlite-storage

How do u write query with condition "LIKE", For example,

I would like to make select few rows where my word colomn rows matches with word_name

normally would like this,

"SELECT rowid AS word_id,word from table WHERE word LIKE '%word_name%' "

using this plugin, in my JS file , i am trying to do like this,

var query = ""SELECT rowid AS word_id,word from table WHERE word LIKE '%(?)%' ""

$cordovaSQLite.execute(DBname, query, [word_name]).then(function(res) {

     });

But this does not work ? any help ??

question doc-todo

Most helpful comment

var query = ""SELECT rowid AS word_id,word from table WHERE word LIKE '%(?)%' ""

$cordovaSQLite.execute(DBname, query, [word_name]).then(function(res) {

 });

First, you have too many double-quote marks in the query string. Second, I found a nice tip how to do this with the Web SQL API here: http://stackoverflow.com/a/17963259

Following that answer, I would suggest you try something like this:

var query = "SELECT rowid AS word_id,word from table WHERE (word LIKE ?)";

$cordovaSQLite.execute(DBname, query, ['%'+word_name+'%']).then(function(res) {

});

>All comments

var query = ""SELECT rowid AS word_id,word from table WHERE word LIKE '%(?)%' ""

$cordovaSQLite.execute(DBname, query, [word_name]).then(function(res) {

 });

First, you have too many double-quote marks in the query string. Second, I found a nice tip how to do this with the Web SQL API here: http://stackoverflow.com/a/17963259

Following that answer, I would suggest you try something like this:

var query = "SELECT rowid AS word_id,word from table WHERE (word LIKE ?)";

$cordovaSQLite.execute(DBname, query, ['%'+word_name+'%']).then(function(res) {

});
Was this page helpful?
0 / 5 - 0 ratings