Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for POINT class #877

Closed
wants to merge 2 commits into from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/protocol/SqlString.js
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
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