Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ public static Number decodeNumber(ByteBuf buffer, PostgresqlObjectId dataType, @
return Short.parseShort(ByteBufUtils.decode(buffer));
case INT4:
case INT4_ARRAY:
case OID:
case OID_ARRAY:
if (FORMAT_BINARY == format) {
return buffer.readInt();
}
return Integer.parseInt(ByteBufUtils.decode(buffer));
case INT8:
case INT8_ARRAY:
case OID:
case OID_ARRAY:
if (FORMAT_BINARY == format) {
return buffer.readLong();
}
Expand Down
11 changes: 9 additions & 2 deletions 11 src/test/java/io/r2dbc/postgresql/codec/LongCodecUnitTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@

import static io.r2dbc.postgresql.client.EncodedParameter.NULL_VALUE;
import static io.r2dbc.postgresql.client.ParameterAssert.assertThat;
import static io.r2dbc.postgresql.codec.PostgresqlObjectId.INT8;
import static io.r2dbc.postgresql.codec.PostgresqlObjectId.VARCHAR;
import static io.r2dbc.postgresql.codec.PostgresqlObjectId.*;
import static io.r2dbc.postgresql.message.Format.FORMAT_BINARY;
import static io.r2dbc.postgresql.message.Format.FORMAT_TEXT;
import static io.r2dbc.postgresql.util.ByteBufUtils.encode;
Expand All @@ -49,6 +48,14 @@ void decode() {

assertThat(codec.decode(TEST.buffer(8).writeLong(100L), dataType, FORMAT_BINARY, Long.class)).isEqualTo(100L);
assertThat(codec.decode(encode(TEST, "100"), dataType, FORMAT_TEXT, Long.class)).isEqualTo(100L);

/* According to documentation: "The oid type is currently implemented as an unsigned four-byte integer"
* (https://www.postgresql.org/docs/12/datatype-oid.html).
* There is no "unsigned four-byte integer" common type in java, so the closest type to hold all possible oid
* values is long. 2314556683 is a valid oid for example.
*/
assertThat(codec.decode(encode(TEST, "2314556683"), OID.getObjectId(), FORMAT_TEXT, Long.class))
.isEqualTo(2314556683L);
}

@Test
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.