Fix find with NaN id in base-sql

This commit is contained in:
Anatoliy Chakkaev 2013-04-22 08:44:31 +04:00 committed by Raymond Feng
parent e13149edc5
commit 8099f7edf2
1 changed files with 5 additions and 1 deletions

View File

@ -62,8 +62,12 @@ BaseSQL.prototype.exists = function (model, id, callback) {
};
BaseSQL.prototype.find = function find(model, id, callback) {
var idNumber = Number(id);
if (isNaN(idNumber)) {
callback(new Error('id is not a number'));
}
var sql = 'SELECT * FROM ' +
this.tableEscaped(model) + ' WHERE ' + this.escapeName('id') + ' = ' + Number(id) + ' LIMIT 1';
this.tableEscaped(model) + ' WHERE ' + this.escapeName('id') + ' = ' + idNumber + ' LIMIT 1';
this.query(sql, function (err, data) {
if (data && data.length === 1) {