Steve Holden <[EMAIL PROTECTED]> writes:

> ... and if wishes were horses then beggars would ride :)

This is a problem with MySQL.  Other databases work just fine, Steve.  There's
now wishing.  This is a *bug* with MySQL.  Look at how PostgreSQL behaves
correctly (I'd say, then, that their beggars are more productive because the
*DO* have horses...):


teste=# SHOW server_encoding ;
 server_encoding 
-----------------
 UTF8
(1 registro)

teste=# show client_encoding ;

 client_encoding 
-----------------
 UTF8
(1 registro)

teste=# create table char_test (test_col char(1));
CREATE TABLE
teste=# insert into char_test values ('ç');
INSERT 0 1
teste=# insert into char_test values ('ã');
INSERT 0 1
teste=# insert into char_test values ('²');
INSERT 0 1
teste=# insert into char_test values ('¤');
INSERT 0 1
teste=# insert into char_test values ('¼');
INSERT 0 1
teste=# insert into char_test values ('¾');
INSERT 0 1
teste=# insert into char_test values ('ð');
INSERT 0 1
teste=# insert into char_test values ('®');
INSERT 0 1
teste=# select * from char_test;
 test_col 
----------
 ç
 ã
 ²
 ¤
 ¼
 ¾
 ð
 ®
(8 registros)


Try the same with MySQL and recover these chars with Python.

teste=# alter table char_test add column id serial not null;
NOTICE:  ALTER TABLE will create implicit sequence "char_test_id_seq" for 
serial column "char_test.id"
ALTER TABLE
teste=# select * from char_test;
 test_col | id 
----------+----
 ç        |  1
 ã        |  2
 ²        |  3
 ¤        |  4
 ¼        |  5
 ¾        |  6
 ð        |  7
 ®        |  8
 µ        |  9
(9 registros)



>>> from sqlobject import *
>>> uri = 'postgres://localhost/teste'
>>> sqlhub.processConnection = connectionForURI(uri)
>>> class CharTest(SQLObject):
...     testCol = UnicodeCol()
... 
>>> list(CharTest.select())
[<CharTest 1 testCol=u'\xe7'>, <CharTest 2 testCol=u'\xe3'>, <CharTest 3 
testCol=u'\xb2'>, <CharTest 4 testCol=u'\xa4'>, <CharTest 5 testCol=u'\xbc'>, 
<CharTest 6 testCol=u'\xbe'>, <CharTest 7 testCol=u'\xf0'>, <CharTest 8 
testCol=u'\xae'>, <CharTest 9 testCol=u'\xb5'>]
>>> ct = CharTest.select()
>>> for ct_instance in ct:
...    print ct_instance
... 
<CharTest 1 testCol=u'\xe7'>
<CharTest 2 testCol=u'\xe3'>
<CharTest 3 testCol=u'\xb2'>
<CharTest 4 testCol=u'\xa4'>
<CharTest 5 testCol=u'\xbc'>
<CharTest 6 testCol=u'\xbe'>
<CharTest 7 testCol=u'\xf0'>
<CharTest 8 testCol=u'\xae'>
<CharTest 9 testCol=u'\xb5'>
>>> for ct_instance in ct:
...    print ct_instance.testCol
... 
ç
ã
²
¤
¼
¾
ð
®
µ
>>> 



It's all there, all UTF-8.  And the same holds true when I specify the size of
the column in Python as well:

>>> from sqlobject import *
>>> uri = 'postgres://localhost/teste'
>>> sqlhub.processConnection = connectionForURI(uri)
>>> class CharTest2(SQLObject):
...    class sqlmeta:
...       table = 'char_test'
...    testCol = UnicodeCol(length=1)
... 
>>> list(CharTest2.select())
[<CharTest2 1 testCol=u'\xe7'>, <CharTest2 2 testCol=u'\xe3'>, <CharTest2 3 
testCol=u'\xb2'>, <CharTest2 4 testCol=u'\xa4'>, <CharTest2 5 testCol=u'\xbc'>, 
<CharTest2 6 testCol=u'\xbe'>, <CharTest2 7 testCol=u'\xf0'>, <CharTest2 8 
testCol=u'\xae'>, <CharTest2 9 testCol=u'\xb5'>]
>>> for ct_instance in CharTest2.select():
...    print ct_instance.testCol
... 
ç
ã
²
¤
¼
¾
ð
®
µ
>>> 


Maybe it's time for MySQL to learn horse riding...

-- 
Jorge Godoy      <[EMAIL PROTECTED]>

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to