Search code examples
htmlweb-sqlselect-query

Select Query - WebSQL


I've the following code to select a row.. When I call the function with getRecords("Peter Sam"); one record is shown.. However if I just pass getRecords("Peter"); it says "No results".

  getRecords = function(cname){
        db.transaction(function(tx) {
            tx.executeSql('SELECT * FROM contacts WHERE (cname LIKE ?)', [cname], renderResults);
        });
    }

What is the correct usage of "LIKE" in "Select" query?? BTW where do I refer SQL syntax for WebSQL?

Thanks


Solution

  • In transact SQL you would use a % as a wild card. something like:

    SELECT * FROM contacts WHERE cname LIKE ?%
    

    However, WebSQL has been discontinued so I don't suggest using this method.