-
Notifications
You must be signed in to change notification settings - Fork 26
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
Special characters not quoted in BYTEA columns #1
Comments
Is it valid to escape all of these even when not going into a BYTEA column? I may need to go back and look at the code, but I believe that we do not always know whether a BYTEA value is expected. |
The escaping seems to be accepted:
So I don't think we'll have more breakage by this. On the other hand, I'm suprised varchar supports null chars :) |
An alternative to "quoting everywhere" would be to add such quoting to ByteString fields (on the haskell side), and disallow NULLs in plain Strings. |
I have made commit 6cc0578 that I believe will fix this for you. Please test and let me know. It is rather unclear what level of binary escaping is needed using the C API vs. using psql. Also, it is unclear whether unesaping will have to be done on data come back the other way around. Let me know. Thanks, -- John |
Incidentally, I know that it is possible to efficiently transfer large binary blobs to and from Postgres using libpq without any quoting. I'd have to dig through the docs to figure out how though. |
I would be happy to know what you find out. I had thought I already was doing this, but apparently not. |
Ok, I've uploaded an example of what needs to happen here. |
Reading a ByteString from a bytea field yields the binary data in "bytea Hex Format" as described here: http://www.postgresql.org/docs/9.1/static/datatype-binary.html. This is probably not what one wants. Our fork (https://github.com/soenkehahn/hdbc-postgresql) fixes this by converting bytestrings to "Hex Format" before writing them to the DB and decoding the format when reading. And comments on that? |
Hi,
It seems that the BYTEA/ByteString column type doesn't quote "special" characters properly, which results in silent data truncation at the first NULL character.
Sample table:
Sample program:
The statements as received by the postgres server are:
As you can see, the bindings do not correctly escape the NULL bytes and this results in silent truncation. The proper escaping rules for BYTEA columns are documented here: http://www.postgresql.org/docs/8.4/static/datatype-binary.html
thanks,
iustin
The text was updated successfully, but these errors were encountered: