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 UUID columns across more databases #46

Merged
merged 2 commits into from
Mar 1, 2017
Merged

Conversation

gregghz
Copy link
Collaborator

@gregghz gregghz commented Feb 23, 2017

Postgres returns a concrete java.util.UUID where MySQL returns a
byte array. This should improve support for any databases that support
a native UUID column type.

fixes #45

Postgres returns a concrete `java.util.UUID` where MySQL returns a
byte array. This should improve support for any databases that support
a native UUID column type.
case x: Array[Byte] => x
case x: Blob => x.getBytes(0, x.length.toInt)
case x: Clob => x.getSubString(1, x.length.asInstanceOf[Int]).getBytes
case x: String => x.toCharArray.map(_.toByte)
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe if it is a string it should be treated a s dash-seperated hex-encoded UUID?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're probably right, but that would be a change that breaks the API. This code is taken from the implementation of byteArrayOption which is what uuid used to use.

@pauldraper
Copy link
Contributor

Thoughts:

(1) This is why I don't like SqlRow#extractOption(). Code browsing makes me 90% sure this would work if we had called ResultSet#getBytes(), instead of asking the driver for whatever format it pleased. https://github.com/pgjdbc/pgjdbc/blob/master/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java#L2376-L2403

(2) I'd rather we stick to the JDBC types. We got in trouble because we had a bright idea (UUIDs) that didn't always work. If we have logic we'd like to add to the standard JDBC interface, it should be in driver-specific projects.

This PR is good; it can only help in our current situation. In relate 3, I'd like fix these mistakes.

@gregghz gregghz merged commit ed07442 into master Mar 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Postgres: uuid column throws a match error
4 participants