Skip to content

[FEATURE REQUEST] Allow sending UUID in binary to database #1582

@knutwannheden

Description

@knutwannheden

Is your feature request related to a problem? If so, please give a short summary of the problem and how the feature would resolve it

I am trying to execute SQL queries with UUID objects in Java mapping to uniqueidentifier values in the database. This works, but when passing a UUID value as an input to a query using PreparedStatement#setObject() the value ends up being transferred as a string over the wire. This is inefficient both computationally (UUID#toString()) and also transfers more data over the network (36 bytes vs. 16 bytes).

Describe the preferred solution

When reading uniqueidentifier values from a ResultSet I can call ResultSet#getObject(int, Class) with the second parameter as UUID.class. This will give back the correct UUID value as expected without first converting the byte array to a String. Essentially I would want to have the same possibility when calling PreparedStatement#setObject() with a UUID object as input.

Describe alternatives you've considered

The alternative (workaround) I now use to do this is to manually convert the UUID value to a byte[] value (essentially using the same logic as in Util#asGuidByteArray(UUID)) and then give that byte[] object to PreparedStatement#setObject().

Additional context

Looking at the code I found this relevant block:

if (JDBCType.GUID == jdbcType) {
if (null != cryptoMeta) {
if (value instanceof String) {
value = UUID.fromString((String) value);
}
byte[] bArray = Util.asGuidByteArray((UUID) value);
op.execute(this, bArray);
} else {
op.execute(this, String.valueOf(value));
}

Apparently it looks like what I want is possible, but only when cryptoMeta is set. I don't understand how encryption is related to this.

Reference Documentations/Specifications

Reference Implementation

Metadata

Metadata

Assignees

No one assigned

    Labels

    BacklogThe topic in question has been recognized and added to development backlogEnhancementAn enhancement to the driver. Lower priority than bugs.

    Type

    No type

    Projects

    Status

    Closed Issues

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions