Skip to content

patch for geometry type #301

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

Merged
merged 2 commits into from
Oct 13, 2012
Merged

patch for geometry type #301

merged 2 commits into from
Oct 13, 2012

Conversation

croquiscom
Copy link

for issue #299

I made a patch and test for geometry type.

There is a strange point.
For insertion, I give a buffer of WKBPoint type (1 byte for byte-order, 4 byte for type, 8 byte for x, 8 byte for y)
But when I fetch it from the database, I get four more bytes of zero in front of the buffer.

I can not find any information about this in the MySQL packet documentation.
(is it right to return first-four-bytes-removed buffer? hmm..)

@croquiscom
Copy link
Author

I thought about returning an object instead of a buffer. (like Date type)
But I can not determine which one is better, [x,y] or {x:x, y:y}, so I let it be.

By the way, if I do so and someone does not want converted object, then someone may use { typeCast: false } option.
But { typeCast: false } option give a string always.

How about check whether it is a binary or not when typeCast:false?

// in RowDataPacket.prototype.parse

var value = (typeCast)
  ? this._typeCast(fieldPacket, parser)
  : (field.charsetNr === Charsets.BINARY
    ? parser.parseLengthCodedBuffer()
    : parser.parseLengthCodedString());

@felixge
Copy link
Collaborator

felixge commented Oct 11, 2012

A few thoughts:

  • There is a type casting test that has all kinds of types in it, can you add your test case in there, rather than adding a new one?
  • IMO casting into {x: x, y: y} seems like a great default - please do that
  • Type casting into buffers when typeCast: false seems like a great idea for binary fields as well as this geometry stuff you have here.

Let me know what you think! Thanks for the help!

@croquiscom
Copy link
Author

I worked as you wrote.

One problem of returning object is that the client cannot distinguish an object is a linestring or a multipoint,
though it may not be a problem for most cases because the client may know the data type of the column.

@felixge
Copy link
Collaborator

felixge commented Oct 13, 2012

Ok, I'm not perfectly happy with your implementation as you're essentially doing stuff manually that is supposed to be handled by the parser class (incrementing the internal buffer offset, providing high level parse functions).

But that being said ... it doesn't interfere with anything I care about and the test is good - so I'm merging. If you want to extend the parser to include the float/other types you need and improve the code ... that would still be seriously kick ass : ).

felixge added a commit that referenced this pull request Oct 13, 2012
@felixge felixge merged commit 3ba2fb6 into mysqljs:master Oct 13, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants