-
Notifications
You must be signed in to change notification settings - Fork 185
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
Add encoding conversion for all strings sent to the database #231
Comments
cbandy
pushed a commit
to cbandy/ruby-pg
that referenced
this issue
Jan 10, 2020
Previously all strings sent to the server were sent in their internal binary representation, without respecting the character encoding of strings. Now the encoding of all strings is compared with the current connection encoding and converted if they are different. Since coders are independent from any database connection, this adds a second parameter to PG::Coder#encode, that allows to define the destination encoding, which previously was always ASCII_8BIT. This encoding should be set to the connection encoding, in practice. This also adds a lot of tests for encoding and decoding data. This implements issue ged#231 : https://bitbucket.org/ged/ruby-pg/issues/231
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Original report by Lars Kanis (Bitbucket: larskanis, GitHub: larskanis).
Currently the handling of string encoding is asymmetric: All strings that are received from the database are properly tagged with the encoding of the connection. However all strings sent to the database are sent in the internal binary string representation, regardless to which encoding the given string is tagged.
In order to respect the encoding of strings sent to the database, all strings should be converted to the connection encoding, before transmission. This should happen internally in ruby-pg and only if the given string encoding is differently to the connection encoding.
Currently the user is responsible for the right encoding, but it would fit better into ruby-pg.
Since PG::Coder classes are independent to any database connection,
PG::Coder#encode
should get a second parameter, which defines the destination string encoding for the type encoding process. It could be used like this:The text was updated successfully, but these errors were encountered: