Skip to content

Commit 2ac2b18

Browse files
committed
SqlString.escapeId turn arrays to a list of identifiers
1 parent 14b93f7 commit 2ac2b18

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/protocol/SqlString.js

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
var SqlString = exports;
22

33
SqlString.escapeId = function (val, forbidQualified) {
4+
if (Array.isArray(val)) {
5+
return val.map(function(v) {
6+
return SqlString.escapeId(v, forbidQualified);
7+
}).join(', ');
8+
}
9+
410
if (forbidQualified) {
511
return '`' + val.replace(/`/g, '``') + '`';
612
}

test/unit/protocol/test-SqlString.js

+10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ var test = require('utest');
33
var assert = require('assert');
44
var SqlString = require(common.lib + '/protocol/SqlString');
55

6+
test('SqlString.escapeId', {
7+
'arrays are turned into lists': function() {
8+
assert.equal(SqlString.escapeId(['a', 'b', 't.c']), "`a`, `b`, `t`.`c`");
9+
},
10+
11+
'nested arrays are flattened': function() {
12+
assert.equal(SqlString.escapeId(['a', ['b', ['t.c']]]), "`a`, `b`, `t`.`c`");
13+
},
14+
});
15+
616
test('SqlString.escape', {
717
'undefined -> NULL': function() {
818
assert.equal(SqlString.escape(undefined), 'NULL');

0 commit comments

Comments
 (0)