Problem when using LIKE of Sql in AngularJS

1

I've been having trouble searching for my app using AngularJS for a few days now, and I've been able to find out why: In query SQL with LIKE , it just is not getting the parameter as it should. >

My function looks like this:

self.searchAll = function(text) {
  var parameters = [text];

  return DBA.query("SELECT id, place_name FROM tblPlaces WHERE place_name LIKE '%(?)%'", parameters)
    .then(function(result) {
      return DBA.getAll(result);
  });
}

I think that because (?) is pasted with %% , it does not recognize that the text parameter should fit there. I decided to do some tests and put some text directly in the query, without coming by parameter and worked.

I also tried to concatenate the text, to see if that would work, because if it worked I could try to pass the parameter in this way. But it also did not work, it returns me an SQLite error.

Then I had two doubts: Is it possible to do this search using LIKE and getting this text by parameter the way it is there in the function? Or would it be better for me to do a general SELECT, transform into a JSON object, and make use of the Angular filter?

Obs: This search I'm trying to do is on a screen that lists several categories and the user can search for products in general.

    
asked by anonymous 25.08.2016 / 17:36

1 answer

2

I just tested something that had not even crossed my mind: Concatenate the %% with the parameter already in the parameters variable. And it worked!

self.searchAll = function(nameSearch) {
  var parameters = ["%"+nameSearch+"%"];

  return DBA.query('SELECT id, place_name FROM tblPlaces WHERE place_name LIKE ?', parameters)
    .then(function(result) {
      return DBA.getAll(result);
});
}
    
25.08.2016 / 20:03