diff --git a/lib/SqlString.js b/lib/SqlString.js index d4fb470..8c8a0a1 100644 --- a/lib/SqlString.js +++ b/lib/SqlString.js @@ -23,11 +23,13 @@ SqlString.escapeId = function escapeId(val, forbidQualified) { return sql; } + var stringified = (typeof val === 'string') ? val : String(val); + if (forbidQualified) { - return '`' + val.replace(/`/g, '``') + '`'; + return '`' + stringified.replace(/`/g, '``') + '`'; } - return '`' + val.replace(/`/g, '``').replace(/\./g, '`.`') + '`'; + return '`' + stringified.replace(/`/g, '``').replace(/\./g, '`.`') + '`'; }; SqlString.escape = function escape(val, stringifyObjects, timeZone) { diff --git a/test/unit/test-SqlString.js b/test/unit/test-SqlString.js index 044fcac..540c08b 100644 --- a/test/unit/test-SqlString.js +++ b/test/unit/test-SqlString.js @@ -27,6 +27,10 @@ test('SqlString.escapeId', { 'nested arrays are flattened': function() { assert.equal(SqlString.escapeId(['a', ['b', ['t.c']]]), "`a`, `b`, `t`.`c`"); + }, + + 'number is escaped': function() { + assert.equal(SqlString.escapeId(1), '`1`'); } });