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

refactor: merge PgPreparedStatement#setBinaryStream int and long methods #3165

Merged
merged 3 commits into from May 12, 2024

Conversation

lucifer-Technoking
Copy link

The content of the two setBinaryStream methods is almost identical. Combine them to reduce code complexity

checkClosed();

if (value == null) {
setNull(parameterIndex, Oid.BYTEA);
Copy link
Member

Choose a reason for hiding this comment

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

this was setNull(parameterIndex, Types.VARBINARY); in the first method

Copy link
Author

Choose a reason for hiding this comment

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

I see, but in method setNull(int parameterIndex, int sqlType), “Types.VARBINARY” and “Oid.BYTEA” are equivalent.

case Types.BINARY:
case Types.VARBINARY:
case Types.LONGVARBINARY:
   oid = Oid.BYTEA;
   break;

Copy link
Member

Choose a reason for hiding this comment

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

Good catch, I'll withdraw my criticism

Copy link
Author

Choose a reason for hiding this comment

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

glad to help with the improvement of PG

Copy link
Member

Choose a reason for hiding this comment

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

This should be a constant from java.sql.Types, not an Oid.
So Oid.BYTEA is not valid here, and it causes tests to fail.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for the reminder. I made a mistake.
I confused PrepareStatement.setNull and preparedParameters.setNull, PrepareStatement.setNull should never use oid as a parameter.

@vlsi vlsi changed the title merge two setBinaryStream methods refactor: merge PgPreparedStatement#setBinaryStream int and long methods May 12, 2024
@vlsi vlsi merged commit d12b625 into pgjdbc:master May 12, 2024
15 of 16 checks passed
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

3 participants