Using the command line sqlite3 utility: I created a table as follows:
CREATE TABLE IF NOT EXISTS
Security (
userId TEXT NOT NULL,
totalHash TEXT NOT NULL,
accessType TEXT NOT NULL,
PRIMARY KEY (userId, totalHash)
);
Then insert 1 row.
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
JavaScript code in node.js to do the same 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');
}
}
);
Returns this:
userId=bill, totalHash=768caa1c468991cb0a0be1cf1d67f6783c56b529ef843e7e43870be1c75db9977c3cc0db6d4ea3a9c02ec542311180a49a85440ae1182dc6ab115ecdb240e208
{ [Error: SQLITE_RANGE: bind or column index out of range] errno: 25, code: 'SQLITE_RANGE' }
It works from the command line, but not via the JS to sqlite binding. Any ideas why?