From 0b4937058d52b337f0d630b9f29e43b1184cf4a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Krolow?= Date: Sat, 21 Jun 2014 13:50:12 -0300 Subject: [PATCH] Fixing escapeId for non integers id Currently at basesql in compoundjs it does not allow one id to be string, but in mysql we can have it! So basically in this commit we enable mysql adapter to handle strings as ids --- lib/mysql.js | 14 +++++++++--- test/connection.test.js | 50 ++++++++++++++++++++++++----------------- 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/lib/mysql.js b/lib/mysql.js index 05b7edd..895d4ff 100644 --- a/lib/mysql.js +++ b/lib/mysql.js @@ -317,6 +317,14 @@ MySQL.prototype.escapeName = function (name) { return '`' + name.replace(/\./g, '`.`') + '`'; }; +MySQL.prototype.escapeId = function (id) { + if (isNaN(id) || this.schema.settings.slave) { + return '"' + ('undefined' === typeof id ? '' : id.toString().replace(/["\n]/g, '')) + '"'; + } + + return Number(id); +}; + MySQL.prototype.all = function all(model, filter, callback) { var sql = 'SELECT * FROM ' + this.tableEscaped(model); @@ -1013,7 +1021,7 @@ function buildWhrSet() { } MySQL.prototype.update = function all(model, filter, callback) { - + var queryresulterr=[]; var queryresultinfo=[]; var querynum=0; @@ -1025,7 +1033,7 @@ MySQL.prototype.update = function all(model, filter, callback) { if (!Array.isArray(filter)) filter = [filter]; - + for (var i = 0; i