fix(pg-native): send Buffer parameters as bytea hex so no byte is lost - #3779
Closed
nigrosimone wants to merge 1 commit into
Closed
nigrosimone wants to merge 1 commit into
nigrosimone wants to merge 1 commit into
Conversation
Contributor
Author
|
Closing: the hex form is right for a bytea column but wrong for a text one, and the test for #675 inserts a Buffer into a TEXT column and expects the text. Without a binary parameter format from node-libpq the two cannot both work, so the fix belongs in node-libpq. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #980. libpq gets every parameter as a C string, so a Buffer is read as utf8 and cut at its first zero byte:
SELECT $1::byteawithdd 56 00 33 00returnsef bf bd 56. pg sends the same Buffer in the binary format and returns it intact.pg-native now turns a Buffer into the hex form bytea accepts,
\x..., before handing the values to libpq, at every call that takes parameters: query, execute, the sync forms and the pipelined batch. Sending it in the binary format would need node-libpq to take a format per parameter, which it does not.The added test sends a Buffer with a zero byte through a query, a prepared statement and the sync forms: it fails on master and passes here.