-
Notifications
You must be signed in to change notification settings - Fork 894
fix: EOFException on PreparedStatement#toString with unset bytea parameter since 42.7.4 #3369
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you keep the old method names and signatures?
From javadoc, I'd assume this was on purpose. @kimjand could you comment on this? Would be great if we can get the fix into next release, as this blocks our update to recent versions. |
On 20-03-2025 14:32, Rico Neubauer wrote:
Could you keep the old method names and signatures?
@kimjand <https://github.com/kimjand> added a method, that
differs from existing one (see javadoc), not sure what you @vlsi
<https://github.com/vlsi> mean with keeping the old names?
Instead of using toStringLiteral() use toString()
From javadoc, I'd assume this was on purpose. @kimjand <https://
github.com/kimjand> could you comment on this?
Yes, this was completely intentional. The core of this bug is that the
driver can't decide on what the methods are supposed to do. ToString
claims it provides human readable output, but the driver expects it to
contain literals for the parameter values.
Now there is a clear distinction between the two cases.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me the change looks good (I would probably refactor all usages of tostring() as it’s confusing to me to have it carry transactional important and stateful logic but this way I guess it’s less overall change)
I'm working on this. Please let me have a couple of days more |
pgjdbc/src/main/java/org/postgresql/core/v3/CompositeQuery.java
Outdated
Show resolved
Hide resolved
Looks like for @Nullable ParameterList params; // optional
boolean standardConformingStrings;
boolean idempotent; // == skipInputStreams I wonder if we use an interface for it instead of (boolean, boolean) parameters? Currently we have String toString(@Nullable ParameterList params, boolean standardConformingStrings);
String toExecutable(@Nullable ParameterList params, boolean standardConformingStrings); What if we go for the following? interface SqlContext {
boolean getStandardConformingStrings();
boolean getIdempotent();
}
@Deprecated
String toString(@Nullable ParameterList params, boolean standardConformingStrings);
String toString(@Nullable ParameterList params, SqlContext context); |
pgjdbc/src/main/java/org/postgresql/core/v3/SqlSerializationContext.java
Show resolved
Hide resolved
I'm happy with the current state of the PR. |
* Returns string representation of the query, substituting particular parameter values for | ||
* parameter placeholders. | ||
* | ||
* <p>Note: the method will replace all the parameters, so it should not be used only once |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so it should not be used only once
seems wrong ... did you mean so it should only be used once
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. The doc was outdated as the behaviour is configurable via SqlSerializationContext
parameter. I will drop the note and add @param context specifies configuration for converting the parameters to string
pgjdbc/src/main/java/org/postgresql/core/v3/DefaultSqlSerializationContext.java
Show resolved
Hide resolved
LGTM |
…meter since 42.7.4 Previously, PgPreparedStatement#toString() could consume InputStream parameters, so it caused exceptions when executing the query later. Fixes #3365 Co-authored-by: Kim Johan Andersson <31474178+kimjand@users.noreply.github.com>
Test case reproducing issue of #3365.
Fix by @kimjand