简体   繁体   English

sqlite-无法使用WHERE子句查询Web数据库

[英]sqlite - unable to query web db with WHERE clause

I'm using the WHERE clause while trying to query my sqlite database. 我在尝试查询我的sqlite数据库时使用了WHERE子句。 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. 我已经尝试在条件值周围使用单引号和双引号,但是我返回的行数仍然为0。

Javascript: 使用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 SQLite数据库

在此处输入图片说明

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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