简体   繁体   中英

sqlite - unable to query web db with WHERE clause

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

在此处输入图片说明

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM