Browse files

Properly format arrays (for e.g. ".. WHERE id IN (?)", [ array ] quer…

…ies)

Ported changes made by https://github.com/blkcat on his fork to latest mysql version.
Updated legacy test to work with new way of handling arrays as commented on issue #85
#85
  • Loading branch information...
1 parent 0383ec5 commit c79c3f3eb16012316ba8cd0d0aeea474a16c4f52 Roger Castells committed Mar 11, 2012
Showing with 7 additions and 1 deletion.
  1. +6 −0 lib/client.js
  2. +1 −1 test/unit/legacy/test-client.js
View
6 lib/client.js
@@ -162,6 +162,8 @@ Client.prototype.format = function(sql, params) {
};
Client.prototype.escape = function(val) {
+ var escape = this.escape;
+
if (val === undefined || val === null) {
return 'NULL';
}
@@ -171,6 +173,10 @@ Client.prototype.escape = function(val) {
case 'number': return val+'';
}
+ if (Array.isArray(val)) {
+ var sanitized = val.map( function( v ) { return escape( v ); } );
+ return "'" + sanitized.join( "','" ) + "'";
+ }
if (typeof val === 'object') {
val = (typeof val.toISOString === 'function')
? val.toISOString()
View
2 test/unit/legacy/test-client.js
@@ -41,7 +41,7 @@ test(function escape() {
assert.equal(client.escape(true), 'true');
assert.equal(client.escape(5), '5');
assert.equal(client.escape({foo:'bar'}), "'[object Object]'");
- assert.equal(client.escape([1,2,3]), "'1,2,3'");
+ assert.equal(client.escape([1,2,3]), "'1','2','3'");
assert.equal(client.escape(new Date(Date.UTC(2011,6,6,6,6,6,6))), "'2011-07-06T06:06:06.006Z'");
assert.equal(client.escape('Super'), "'Super'");

0 comments on commit c79c3f3

Please sign in to comment.