-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
[Postgresql] Hangul(Korean alphabet) encoding problem #66
Comments
I've tried to reproduce this on macOS and I get the following: (require '[babashka.pods :as p])
(p/load-pod 'org.babashka/postgresql {:version "0.1.3"})
(require '[pod.babashka.postgresql :as pg])
(def db {:dbtype "postgresql"
:host "localhost"
:dbname "postgres"
:user "test"
:password "test"
:port 5432})
(prn (-> (pg/execute! db ["SELECT '안녕?' as foo"])
first
:foo)) The output is |
I tried it on WSL2 as you suggested. When I tested connecting to the PostgreSQL server on the host machine from WSL2, it worked fine. 👀 It can be considered an issue that occurs only on Windows. Thanks, |
Can you try this: (require '[babashka.pods :as p])
(p/load-pod 'org.babashka/postgresql {:version "0.1.3"})
(require '[pod.babashka.postgresql :as pg])
(def db {:dbtype "postgresql"
:host "localhost"
:dbname "postgres"
:user "test"
:password "test"
:port 5432})
(spit "foo.txt"
(-> (pg/execute! db ["SELECT '안녕?' as foo"])
first
:foo)) and then look with a text editor (e.g. VSCode) in the file |
Can you test just writing the string directly to the file without the database to see if the same problem occurs? Perhaps it's not even a sql pod issue. Thanks |
Have you tried pod version 0.1.3 on Windows? |
Yes, all attempts were made on Windows. Pod version 0.1.3 was also tested on Windows. So far, the issue has occurred on Windows, but there were no problems in WSL2. |
Could you maybe also test hsqldb on Windows with pod version 0.1.3? If that works then we know that it is a specific problem with the postgres pod on Windows |
Yes, no problem. I will test it and let you know. |
Interesting |
I think it makes sense to upgrade all the builds to use Oracle GraalVM latest (23), add a test for this and then see what happens. It could be a matter of setting |
One more idea, it could be that the problem is with string encoding via the single arg constructor: Can you try in your version of bb the following:
to see if you see a different result? |
First, I tested it with the code you provided. I also saved it as a file, and both the file size and the data were identical. I think the values are changing in the process of transferring the data to the database. (pg/execute! db ["CREATE TABLE IF NOT EXISTS foo (text VARCHAR(256))"])
(pg/execute! db ["INSERT INTO foo (text) VALUES (?)" (String. (.getBytes "안녕?"))])
(pg/execute! db ["INSERT INTO foo (text) VALUES (?)" (String. (.getBytes "안녕?")
java.nio.charset.StandardCharsets/UTF_8)]) I'm not sure if I fully understood your code, but it seems that you're simply passing the values to babashka-sql-pods/src/pod/babashka/sql.clj Lines 71 to 78 in 5eb5203
Thanks, |
I didn't mean that you would insert the result into the database. The original output looks similar to this:
so I think it's a encoding mismatch somewhere. I read that from JDK18 onwards the default encoding is UTF-8 unless otherwise specified so this might fix it. Currently the SQL pods are still built using JDK11, so upgrading should help. I'll try to reproduce this problem on my own Windows machine. Thanks for your patience. |
! This is my first time submitting a GitHub issue. Please let me know if anything is inappropriate, and I appreciate your understanding.
Problem
Description:
Environment:
deps.edn:
main.clj:
result:
[{:?column? "안녕?"}]
expected:
[{:?column? "안녕?"}]
plus:
After inserting Hangul (Korean) data and querying it in psql, the encoding appears to be corrupted.
Server & Client encoding configuration
(pg/execute! db ["show server_encoding;"])
[{:server_encoding "UTF8"}]
(pg/execute! db ["show client_encoding;"])
[{:client_encoding "UTF8"}]
Comparative experiment
Thanks.
The text was updated successfully, but these errors were encountered: