Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/protocol/SqlString.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ SqlString.escape = function(val, stringifyObjects, timeZone) {
}

if (typeof val === 'object') {
// for the mysql point class
if(val.hasOwnProperty('x') && val.hasOwnProperty('y')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also make this a little less risky by saying "if it has x and y and no other properties"

return 'POINT(' + [val.x, val.y].map(parseFloat).join(',') + ')';
}
if (stringifyObjects) {
val = val.toString();
} else {
Expand Down
8 changes: 7 additions & 1 deletion test/unit/protocol/test-SqlString.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,13 @@ test('SqlString.escape', {

assert.strictEqual(string, "'" + expected + "'");
},

'points are converted to POINT objects': function() {
var expected = 'POINT(123.004, -10.1)';
var input = {x: 123.004, y: -10.1};
var string = SqlString.escape(input);

assert.strictEqual(string, expected);
},
'buffers are converted to hex': function() {
var buffer = new Buffer([0, 1, 254, 255]);
var string = SqlString.escape(buffer);
Expand Down