diff --git a/lib/sql.js b/lib/sql.js index 6eea5842..b83303f1 100644 --- a/lib/sql.js +++ b/lib/sql.js @@ -43,7 +43,7 @@ BaseSQL.prototype.defineProperty = function (model, prop, params) { }; BaseSQL.prototype.save = function (model, data, callback) { - var sql = 'UPDATE ' + this.tableEscaped(model) + ' SET ' + this.toFields(model, data) + ' WHERE ' + this.escapeName('id') + ' = ' + data.id; + var sql = 'UPDATE ' + this.tableEscaped(model) + ' SET ' + this.toFields(model, data) + ' WHERE ' + this.escapeName('id') + ' = ' + Number(data.id); this.query(sql, function (err) { callback(err); @@ -53,7 +53,7 @@ BaseSQL.prototype.save = function (model, data, callback) { BaseSQL.prototype.exists = function (model, id, callback) { var sql = 'SELECT 1 FROM ' + - this.tableEscaped(model) + ' WHERE ' + this.escapeName('id') + ' = ' + id + ' LIMIT 1'; + this.tableEscaped(model) + ' WHERE ' + this.escapeName('id') + ' = ' + Number(id) + ' LIMIT 1'; this.query(sql, function (err, data) { if (err) return callback(err); @@ -63,7 +63,7 @@ BaseSQL.prototype.exists = function (model, id, callback) { BaseSQL.prototype.find = function find(model, id, callback) { var sql = 'SELECT * FROM ' + - this.tableEscaped(model) + ' WHERE ' + this.escapeName('id') + ' = ' + id + ' LIMIT 1'; + this.tableEscaped(model) + ' WHERE ' + this.escapeName('id') + ' = ' + Number(id) + ' LIMIT 1'; this.query(sql, function (err, data) { if (data && data.length === 1) { @@ -77,7 +77,7 @@ BaseSQL.prototype.find = function find(model, id, callback) { BaseSQL.prototype.destroy = function destroy(model, id, callback) { var sql = 'DELETE FROM ' + - this.tableEscaped(model) + ' WHERE ' + this.escapeName('id') + ' = ' + id; + this.tableEscaped(model) + ' WHERE ' + this.escapeName('id') + ' = ' + Number(id); this.command(sql, function (err) { callback(err);