0

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?

1 Answer 1

1

Try this in second line.

 Db.get("SELECT * FROM Security WHERE userID=? AND totalHash=? AND accessType='login' LIMIT 1", [userId, totalHash],
Sign up to request clarification or add additional context in comments.

2 Comments

That got rid of the error, but now its not returning anything. The row variable is always undefined. I even tried the named parameters approach and it also doesn't produce the error, but still produces no output. Of the 3 ways listed in the API to specify the call, my first attempt errors out and the two remaining ways produce no output. The fact that there's a difference seems to point to an issue with the binding code.
It does work in my pc. row = [object Object] when there is a match and row = undefined when there is no match.

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.