node.js node-sqlite3 error

I got this wonderful error when setting up CRUD functions on a little node project I’m working on:

{ [Error: SQLITE_RANGE: bind or column index out of range] errno: 25, code: ‘SQLITE_RANGE’ }

Here is the code that caused the error:

var row_update = function(index, name, password, comment, callback) {

var update = db.prepare("UPDATE workers SET name = '?', password = '?', comment = '?' WHERE id = '?'");

update.run(name, password, comment, index, function(err) {
if (err) {
console.log(err);
callback(err);

} else {
callback(0);
}
});
}

The problem here is that I enclosed the question mark placeholders in single quotes:

var update = db.prepare("UPDATE workers SET name = '?', password = '?', comment = '?' WHERE id = '?'");

Here is the corrected code which executes without error:

var row_update = function(index, name, password, comment, callback) {

    var update = db.prepare("UPDATE workers SET name = ?, password = ?, comment = ? WHERE id = ?");

    update.run(name, password, comment, index, function(err) {
        if (err) {
            console.log(err);
            callback(err);

        } else {
            callback(0);
        }
    });
}

greetz

Leave a Reply

Your email address will not be published.