0

I'm using the WHERE clause while trying to query my sqlite database. I know there is data in the db which I should be able to retrieve based on the conditionals in my query, but I can't seem to get it to work.

When I query without conditionals...

sql = 'select LocationGUID, ID, Fullname FROM tblUser';

I'm able to return all the data from the selected columns. Is this is a quotation issue? I've tried single and double-quotes around the conditional values but the number of rows I return is still 0.

Javascript:

sql = 'select LocationGUID, ID, Fullname FROM tblUser WHERE UserName=\'mike\' AND Password=\'mike123\'';

mydb = getDBConn();
mydb.transaction(function(tx) {tx.executeSql(sql, [], function(tx,results) {
var size = results.rows.length;

console.log(size);

for (var i=0;i<size;i++) {
    for (var key in results.rows.item(0)){
         var row = results.rows.item(i);
         console.log(row[key]);
    }
}

SQLite DB

enter image description here

2
  • What is the output of SELECT UserName, typeof(UserName), hex(UserName) FROM tblUser for this row? Commented Sep 3, 2014 at 17:09
  • mike text 6D696B6520202020202020202020202020202020 Commented Sep 3, 2014 at 17:20

1 Answer 1

1

The correct query to find this row would be this:

SELECT ... FROM tblUser WHERE UserName = 'mike                ' AND ...

You might want to change the code that stores the data to remove these unwanted spaces.

To fix the database, use something like this:

UPDATE tblUser SET UserName = rtrim(UserName)
Sign up to request clarification or add additional context in comments.

1 Comment

This worked perfectly, thank you! I tried double-clicking the UserName and Password values to see if there were any empty spaces but nothing was hi-lighted in blue. The SELECT hex() query works great and I will have to remember it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.