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

feat: support getObject(int, byte[].class) for bytea #3274

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

anesterenok
Copy link

@anesterenok anesterenok commented May 27, 2024

New Feature Submissions:

  1. Does your submission pass tests?
    yes
  2. Does ./gradlew styleCheck pass ?
    yes
  3. Have you added your new test classes to an existing test suite in alphabetical order?
    I did, though they weren't

Changes to Existing Features:

  • Does this break existing behaviour? If so please explain.
    no
  • Have you added an explanation of what your changes do and why you'd like us to include them?
    see Feature: please support getObject(int, byte[].class) for bytea #3269
  • Have you written new tests for your core changes, as applicable?
    yes
  • Have you successfully run tests with your changes locally?
    yes

All Submissions:

  • Have you followed the guidelines in our Contributing document?
    yes
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
    yes

@@ -3875,6 +3875,13 @@ public void updateArray(String columnName, @Nullable Array x) throws SQLExceptio
throw new PSQLException(GT.tr("conversion to {0} from {1} not supported", type, getPGType(columnIndex)),
PSQLState.INVALID_PARAMETER_VALUE);
}
} else if (type == byte[].class) {
if (sqlType == Types.BINARY) {
Copy link
Member

Choose a reason for hiding this comment

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

How about Types.VARBINARY, Types.LONGVARBINARY?

Copy link
Author

@anesterenok anesterenok May 28, 2024

Choose a reason for hiding this comment

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

I thought about it, but decided against because Blob only checks for BINARY. Besides, sqlType here is what PG thinks is appropriate for BYTEA, its not a user input, so actually it should never (?) be multiple values.
Do you think other *BINARY values are needed here?

Copy link
Member

Choose a reason for hiding this comment

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

If someone stored VARBINARY or LONGVARBINARY the driver still needs to be able to handle it

Comment on lines 706 to 707
PreparedStatement insertPS = conn.prepareStatement(TestUtil.insertSQL("table1", "bytea_column", "?"));
try {
Copy link
Member

Choose a reason for hiding this comment

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

WDYT of try-with-resources?

Copy link
Author

Choose a reason for hiding this comment

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

Ok, will do, I just copy-pasted Blob test )

@Test
void getBytea() throws SQLException {
Statement stmt = conn.createStatement();
conn.setAutoCommit(false);
Copy link
Member

Choose a reason for hiding this comment

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

Why autoCommit modification is needed here?

Copy link
Author

Choose a reason for hiding this comment

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

Well, its still copy-paste from getBlob(), but AFAIK without it the select statement could take too much memory: https://postgrespro.ru/list/thread-id/2502309

Copy link
Member

Choose a reason for hiding this comment

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

Right, but you should never run out of memory in this test.

*/
@Test
void getBytea() throws SQLException {
Statement stmt = conn.createStatement();
Copy link
Member

Choose a reason for hiding this comment

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

WDYT of moving the declaration of stmt closer to its usage?

Copy link
Author

Choose a reason for hiding this comment

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

Ok

@vlsi
Copy link
Member

vlsi commented May 27, 2024

The change looks good to me, however I wonder:

  1. Does PreparedStatement.setObject(1, new byte[]{1,2,3}); work? I guess we should keep those aligned
  2. Do we have a documentation page that lists the supported types for getObject(1, ...)?

insertPS.setBytes(1, data);
insertPS.executeUpdate();
} finally {
insertPS.close();
Copy link
Member

Choose a reason for hiding this comment

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

Yes please use try with resources. We are now trying to move all new code to that style

@anesterenok
Copy link
Author

Ok, I think I fixed all comments.

@anesterenok anesterenok requested a review from vlsi May 29, 2024 15:33
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.

None yet

4 participants