fukamachi / caveman

Lightweight web application framework for Common Lisp.
http://8arrow.org/caveman/
776 stars 62 forks source link

Database how to use utf8 #35

Closed LuoZhongYao closed 9 years ago

LuoZhongYao commented 9 years ago

I use README.md ways to use the database, but Chinese all "????????", How do I set up a database to use UTF8, I was Chinese users.

fukamachi commented 9 years ago

What Lisp implementation are you using?

LuoZhongYao commented 9 years ago

ccl and clsql,(clsql:select '|*| :from '|request|)

fukamachi commented 9 years ago

I assume it is an issue of your settings for CCL or CLSQL.

Could you try this code before executing the SQL? (In ~/.ccl-init.lisp or somewhere)

(setf ccl:*default-external-format*
      (ccl:make-external-format :character-encoding :utf-8
                                :line-termination :unix)
      ccl:*default-file-character-encoding* :utf-8
      ccl:*default-socket-character-encoding* :utf-8)

I got a similar problem with Caveman1 on Clozure CL 2 years ago when I used Japanese in templates. I found out that it was not related to any databases but just the encoding for outputting strings.

In your case, it also could be a problem when displaying UTF-8 stuffs.

LuoZhongYao commented 9 years ago

I tried, or garbled. On the network, it was said (clsql: execute-command "SET NAMES utf8").But still garbled. So I switch to cl-mysql, it does not garbled.

(ql:quickload :cl-mysql)
(cl-mysql:connect :host "localhost" :user "xxx" :password "xxx")
(cl-mysql:query "use db;")
(cl-mysql:query "set names utf-8;")
(cl-mysql:query "select * from sometable;")

You can add cl-mysql mysql as the default interface it? Like a lot of people would not be necessary to solve these silly questions.

fukamachi commented 9 years ago

CL-DBI and datafly are the default database libraries. CL-DBI uses cl-mysql as an interface to MySQL.