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

Cannot insert UTF-8 chars #150

Closed
jiriknesl opened this Issue May 2, 2013 · 4 comments

Comments

Projects
None yet
4 participants
@jiriknesl
Copy link

jiriknesl commented May 2, 2013

I connect using:

(defdb skoleni-db (mysql {
:db "skoleni"
:user "root"
:password ""
:host "localhost"
}))

(exec-raw skoleni-db ["SET NAMES 'utf8'"])

Then I create entity

(defentity lectors
(table :lectors)
(database skoleni-db))

When I try to insert new value with UTF chars (Č and ý in this case):

(insert lectors (values [
{:id 3 :name "Petr Černý"}]))

I get error:

Failure to execute query with SQL:
INSERT INTO lectors (name, id) VALUES (?, ?) :: [Petr Černý 3]
SQLException:
Message: Incorrect string value: '\xFD' for column 'name' at row 1
SQLState: HY000
Error Code: 1366
LOAD FAILURE for sprint-is.test.modules.skoleni
Incorrect string value: '\xFD' for column 'name' at row 1

@jiriknesl

This comment has been minimized.

Copy link

jiriknesl commented Nov 11, 2013

I fixed a problem using ?useUnicode=true&characterEncoding=UTF-8 in dbspec :subname

@ytll21

This comment has been minimized.

Copy link

ytll21 commented Jul 17, 2014

I also met this issue. My solution is to re-write mysql function of korma:
(defn mysql
"Add utf-8 support as default"
[{:keys [host port db make-pool?]
:or {host "localhost", port 3306, db "", make-pool? true}
:as opts}](merge {:classname)
:delimiters "`"
:make-pool? make-pool?}
opts))

but I think the better way is to add the encoding as a parameter to the function.

@HeGanjie

This comment has been minimized.

Copy link

HeGanjie commented Sep 1, 2015

Add query string to :db param can solve this

(defdb db (mysql {:db   "dbName?useUnicode=true&characterEncoding=UTF-8"
                  :user "root" :password "pw" :host "localhost"}))
@immoh

This comment has been minimized.

Copy link
Member

immoh commented Sep 1, 2015

As of 0.4.1 you can also pass driver properties in the spec map:

(defdb db (mysql {:db   "dbName" :user "root" :password "pw" :host "localhost"
                  :useUnicode true :characterEncoding "UTF-8"}))

@immoh immoh closed this Sep 1, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment