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

fix Issue # 3169 bytea types not handled in SimpleQuery mode #3187

Closed
wants to merge 1 commit 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
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,12 @@
type = "box";
break;

case Oid.BYTEA:
StreamWrapper wrapper = (StreamWrapper) paramValue;
textValue = ByteConverter.bytesToString(wrapper.getBytes());

Check failure on line 317 in pgjdbc/src/main/java/org/postgresql/core/v3/SimpleParameterList.java

View workflow job for this annotation

GitHub Actions / CheckerFramework

[Task :postgresql:compileJava] [argument] incompatible argument for parameter bytes of ByteConverter.bytesToString. textValue = ByteConverter.bytesToString(wrapper.getBytes()); ^ found : @initialized @nonnull byte @initialized @nullable []
type = "bytea";
break;

default:
return "?";
}
Expand Down
16 changes: 16 additions & 0 deletions pgjdbc/src/main/java/org/postgresql/util/ByteConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ private void grow() {
private static final BigInteger[] BI_TEN_POWERS = new BigInteger[32];
private static final BigInteger BI_TEN_THOUSAND = BigInteger.valueOf(10000);
private static final BigInteger BI_MAX_LONG = BigInteger.valueOf(Long.MAX_VALUE);
private static final char[] HEX_DIGITS = "0123456789abcdef".toCharArray();

static {
for (int i = 0; i < INT_TEN_POWERS.length; i++) {
Expand Down Expand Up @@ -102,6 +103,21 @@ public static int bytesToInt(byte []bytes) {
}
}

/**
* Convert a variable length array of bytes to String
* @param bytes array of bytes that can be decoded as String
* @return String
*/
public static String bytesToString(byte[] bytes) {
StringBuilder sb = new StringBuilder();
sb.append("\\x");
for (int i = 0; i < bytes.length; i++) {
sb.append(HEX_DIGITS[(bytes[i] & 0xf0) >>> 4]);
sb.append(HEX_DIGITS[bytes[i] & 0x0f]);
}
return sb.toString();
}

/**
* Convert a variable length array of bytes to an integer
* @param bytes array of bytes that can be decoded as an integer
Expand Down