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

chinese character's encoding problem #53

Open
toreal opened this issue Nov 8, 2017 · 1 comment
Open

chinese character's encoding problem #53

toreal opened this issue Nov 8, 2017 · 1 comment
Assignees

Comments

@toreal
Copy link

toreal commented Nov 8, 2017

Thank you for your great project. I have some issues about chinese encoding problems.

(a) If the field type is setup as 'varchar'. the saved chinese text will become garbled text.
If I change "connection.ex"
case :unicode.characters_to_binary(value, :utf8, {:utf16 , :little}) do
to
case Codepagex.from_string(value, "VENDORS/MICSFT/WINDOWS/CP950") do
it can solve the problem.

(b) But if the field type is 'nvarchar', the chinese character becomes garbled text.

As I understanding, varchar's encoding is CP950.
nvarchar's encoding is unicode.

That is why have such problem.

(c) But, I face another problem. If the field type is varchar(1), then even english character can not be inserted. To solve this problem, I change "connection.ex"
defp param(value) when is_binary(value) do
{value, nil}
# case :unicode.characters_to_binary(value, :utf8, {:utf16, :little}) do
# {:error, _, _} -> {value, :binary}
# val -> {val, nil}
# end
end

Then, everything look fine including chinese character encoding problem.
My question is whether characters_to_binary is necessary or not. Could I ignore it?

@mjaric
Copy link
Collaborator

mjaric commented Nov 24, 2017

I think we have to convert bitstring to little endian binary representation, that is why we need that call. I'm not sure how SQL server managed to accept it without reversing char bits since for Chinese, if I'm not mistaken, each char takes 2 bytes.

Anyhow. NVARCHAR has to work with this function, I will write some tests since I never checked other codepages and let you know what I found.

@mjaric mjaric self-assigned this Feb 29, 2020
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

2 participants