fix: do not reserve statement name on prepare failure - #4953
Conversation
There was a problem hiding this comment.
Code Review
This pull request improves PGAdapter's handling of prepared statements by checking for duplicate statement names, handling case-insensitive and quoted identifiers, and throwing errors for zero-length delimited identifiers instead of throwing an IllegalStateException. It also adds comprehensive tests to verify these behaviors. The review feedback suggests catching Exception instead of Throwable to avoid swallowing critical JVM errors, and adding a defensive null check on the parsed statement name to prevent potential NullPointerExceptions.
Deregister prepared statements from the connection session if statement analysis fails during PREPARE. This ensures that a failed PREPARE does not reserve the statement name or block subsequent attempts. Also align duplicate prepared statement handling with PostgreSQL: - Return SQLSTATE 42P05 (DuplicatePreparedStatement) instead of dropping the connection on duplicate statement names. - Fold unquoted statement names to lowercase and strip identifier quotes in PREPARE to match EXECUTE and DEALLOCATE behavior. - Reject zero-length delimited identifiers (`PREPARE ""`).
0c0d9ba to
cbe03f3
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request improves the handling of duplicate prepared statements and statement name identifiers in PGAdapter. Instead of throwing an IllegalStateException when a prepared statement name is reused, PGAdapter now gracefully returns a DuplicatePreparedStatement error (42P05) to the client, keeping the original statement intact. Additionally, it adds support for case-folding and unquoting statement identifiers, throwing an error for zero-length delimited identifiers. Comprehensive unit and integration tests have been added to verify these behaviors. I have no additional feedback to provide as the implementation is robust and well-tested.
Deregister prepared statements from the connection session if statement analysis fails during PREPARE. This ensures that a failed PREPARE does not reserve the statement name or block subsequent attempts.
Also align duplicate prepared statement handling with PostgreSQL:
PREPARE "").