Skip to content
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

Closed
ged opened this issue Dec 22, 2015 · 4 comments
Closed

Add encoding conversion for all strings sent to the database #231

ged opened this issue Dec 22, 2015 · 4 comments

Comments

@ged
Copy link
Owner

ged commented Dec 22, 2015

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#encodeshould get a second parameter, which defines the destination string encoding for the type encoding process. It could be used like this:

e = PG::TextEncoder::Array.new
e.encode(['nový'], conn.internal_encoding).encoding  # => #<Encoding:UTF-8>
@ged
Copy link
Owner Author

ged commented Dec 22, 2015

Original comment by Lars Kanis (Bitbucket: larskanis, GitHub: larskanis).


This was created in response to #230 .

@ged
Copy link
Owner Author

ged commented Jan 10, 2016

Original comment by Lars Kanis (Bitbucket: larskanis, GitHub: larskanis).


This feature is implemented by this github PR: #11

@ged
Copy link
Owner Author

ged commented Jan 31, 2016

Original comment by Michael Granger (Bitbucket: ged, GitHub: ged).


This looks good; are the failures on Travis for the 2.0 versions legitimate, though?

@ged
Copy link
Owner Author

ged commented Mar 22, 2016

Original comment by Michael Granger (Bitbucket: ged, GitHub: ged).


Implemented in e61a06f.

@ged ged closed this as completed Mar 22, 2016
@ged ged added this to the Pending milestone Oct 8, 2019
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
Projects
None yet
Development

No branches or pull requests

1 participant