[CLSQL-Help] Problem using UTF-8 strings with clsql on SBCL.

Tomasz Skutnik Tomasz.Skutnik at e-point.pl
Thu Feb 17 13:49:58 MST 2005


Hi.

Here's my problem:

I'm trying to use clsql to build a toy app. Being non-native english 
speaker I want to use my national (polish) characters in my database 
strings. I choosed SBCL + PostgreSQL because they give me UTF-8 out of 
the box (export LANG=pl_PL.UTF-8 does the trick).

However I've stumbled upon following problem (reproduction procedure 
follows):

Create database using UTF-8 encoding (see utftest.sql - it's PostgreSQL 
specific). Evaluating sample code (see uftest.lisp) raises condition 
"The value #\ą is not of type BASE-CHAR." (see trace.txt).

Using psql form shell works fine (INSERT INTO utftest (data) VALUES 
('ą');). It even works using XEmacs sql-interactive-mode (M-x 
sql-postgres). In SBCL I can evaluate/print/use as slot value/ strings 
that contain polish characters (source is UTF-8 encoded) from Slime or 
from shell. Everywhere everything works fine, but trying to pass such 
nonstandard(?) string to clsql breakes.

I've read SBCL internals unicode support wiki page 
(http://sbcl-internals.cliki.net/Unicode) but... I can't grok what does 
it mean for my code and clsql (I've just started learning LISP - it's my 
3rd week, and that issue is just too deep for now). Is this some sort of 
implicit type-conversion problem? FFI problem? Something else? I'm not 
even sure if  I should ask this list or sbcl-devel.

I'm using latest (cvs up -A) CVS slime, SBCL (0.8.19.22) and PostgreSQL 
(7.4.7) from Debian/Unstable. My locale is (pl_PL.UTF-8). I use 
XEmacs+Mule/UCS with following settings: (setq slime-net-coding-system 
'utf-8-unix) (set-default-coding-systems 'utf-8-unix). All attachments 
are UTF-8 encoded.

Any idea what's wrong? Is this a bug? Can it be fixed/worked around? 
Should I ask sbcl-devel?

Any ideas would be appreciated. Sorry for lenghty explanation, but I've 
tried to provide as many usefull details as possible.

Thanks

Tomasz

-------------- next part --------------
The value #\ą is not of type BASE-CHAR.
   [Condition of type TYPE-ERROR]

Restarts:
  0: [ABORT] Abort handling SLIME request.
  1: [DESTROY-THREAD] Destroy this thread (6067)

Backtrace:
  0: (SB-KERNEL:HAIRY-DATA-VECTOR-SET 3 "INSERT INTO utftest (data) VALUES ('   " 36 #\ą)[:EXTERNAL]
  1: (SB-KERNEL:VECTOR-TO-VECTOR* 2 "INSERT INTO utftest (data) VALUES ('ą')" SIMPLE-BASE-STRING)[:EXTERNAL]
  2: ((SB-PCL::FAST-METHOD CLSQL-SYS:DATABASE-EXECUTE-COMMAND (T CLSQL-POSTGRESQL:POSTGRESQL-DATABASE)) #<unavailable argument> #<unavailable argument> "INSERT INTO utftest (data) VALUES ('ą')" #<CLSQL-POSTGRESQL:POSTGRESQL-DATABASE localhost/utftest/utftest OPEN {A4FAD99}>)
  3: ("#'(LAMBDA (SB-PCL::.PV-CELL. SB-PCL::.NEXT-METHOD-CALL. SB-PCL::.ARG0. ...) (DECLARE #) ...)" #<unavailable argument> #<unavailable argument> "INSERT INTO utftest (data) VALUES ('ą')" #<CLSQL-POSTGRESQL:POSTGRESQL-DATABASE localhost/utftest/utftest OPEN {A4FAD99}>)
  4: ((SB-PCL::FAST-METHOD CLSQL-SYS:EXECUTE-COMMAND (STRING)) #<unavailable argument> #<unavailable argument> "INSERT INTO utftest (data) VALUES ('ą')" (:DATABASE #<CLSQL-POSTGRESQL:POSTGRESQL-DATABASE localhost/utftest/utftest OPEN {A4FAD99}>))
  5: ((SB-PCL::FAST-METHOD CLSQL-SYS:EXECUTE-COMMAND (CLSQL-SYS::%SQL-EXPRESSION)) #<unavailable argument> #<unavailable argument> #<CLSQL-SYS::SQL-INSERT INSERT INTO UTFTEST (DATA) VALUES ('ą')> (:DATABASE #<CLSQL-POSTGRESQL:POSTGRESQL-DATABASE localhost/utftest/utftest OPEN {A4FAD99}>))
  6: ((SB-PCL::FAST-METHOD CLSQL-SYS:UPDATE-RECORDS-FROM-INSTANCE (CLSQL-SYS:STANDARD-DB-OBJECT)) (#(NIL NIL) . #()) #<unavailable argument> #<UTFTEST {B636D71}> NIL)
  7: (#:EVAL-TMPFUN-5096 0)[:EXTERNAL]
-------------- next part --------------
;; this file is UTF-8 encoded
(asdf:operate 'asdf:load-op 'clsql)

(clsql:def-view-class utftest ()
  ((data
    :initarg :data
    :type string)))

"ąćęłńóśżźĄĆĘŁŃÓŚŻŹ"
(princ "ąćęłńóśżźĄĆĘŁŃÓŚŻŹ")

(clsql:connect '("localhost" "utftest" "utftest" "utftest") :database-type :postgresql)
(clsql:start-sql-recording)
(clsql:create-view-from-class 'utftest)
(clsql:with-transaction ()
  ;; string contains single 0x0105 unicode character
  ;; (latin small letter a with ogonek - see http://www.unicode.org/charts/PDF/U0100.pdf, pages 2 and 3)
  (let* ((inst (make-instance 'utftest :data "ą")))
    (clsql:update-records-from-instance inst)))
(clsql:stop-sql-recording)
(clsql:disconnect)
-------------- next part --------------
create database utftest encoding = 'UTF-8';
create user utftest with encrypted password 'utftest';

\c utftest
\encoding
-- should display 'UNICODE'


More information about the CLSQL-Help mailing list