node.js / sqlite3 SELECT从命令行运行,但不从JS绑定运行

时间:2013-09-07 15:42:54

标签: javascript node.js sqlite

使用命令行sqlite3实用程序: 我按如下方式创建了一个表:

CREATE TABLE IF NOT EXISTS
Security (
  userId        TEXT NOT NULL,
  totalHash     TEXT NOT NULL,
  accessType    TEXT NOT NULL,
  PRIMARY KEY (userId, totalHash)
);

然后插入1行。

insert into Security (userId, totalHash, accesstype) Values ('bill', '768caa1c468991cb0a0be1cf1d67f6783c56b529ef843e7e43870be1c75db9977c3cc0db6d4ea3a9c02ec542311180a49a85440ae1182dc6ab115ecdb240e208', 'login');

SELECT * FROM Security WHERE userID='bill' AND totalHash='768caa1c468991cb0a0be1cf1d67f6783c56b529ef843e7e43870be1c75db9977c3cc0db6d4ea3a9c02ec542311180a49a85440ae1182dc6ab115ecdb240e208' AND accessType='login' LIMIT 1;
userId      totalHash                                                                                                                         accessType
----------  ---------------------------------------------------------------------------------------------                                     ----------
bill        768caa1c468991cb0a0be1cf1d67f6783c56b529ef843e7e43870be1c75db9977c3cc0db6d4ea3a9c02ec542311180a49a85440ae1182dc6ab115ecdb240e208  login     

node.js中的JavaScript代码执行相同的SELECT:

if (debug) {console.log('userId=' + userId + ', totalHash=' + totalHash);}
Db.get("SELECT * FROM Security WHERE userID=? AND totalHash=? AND accessType='login' LIMIT 1", true, userId, totalHash,
   function (error, row) {
      if (error !== null) {
         if (debug) {console.log(error);}
         res.writeHead(401, {'Content-Type': 'text/plain'});
         res.end('Invalid login');
      } else {
         res.writeHead(200, {'Content-Type': 'text/plain'});
         res.end('Login OK');
      }
   }
);

返回:

userId=bill, totalHash=768caa1c468991cb0a0be1cf1d67f6783c56b529ef843e7e43870be1c75db9977c3cc0db6d4ea3a9c02ec542311180a49a85440ae1182dc6ab115ecdb240e208
{ [Error: SQLITE_RANGE: bind or column index out of range] errno: 25, code: 'SQLITE_RANGE' }

它可以从命令行工作,但不能通过JS到sqlite绑定。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

在第二行尝试这个。

 Db.get("SELECT * FROM Security WHERE userID=? AND totalHash=? AND accessType='login' LIMIT 1", [userId, totalHash],