> you need to get a handle on exactly what is in that column. a small
> test program which retrieves it and prints it out (using no
> conversion) is a good place to start.
I seem to have no problem inserting and retriving data (SA alone).
Having ``convert_unicode=False`` or ``convert_unicode=True`` doesn't
seem to change anything. Or it's just not noticable from my POV as it's
converted back and forth before it's stored/retrived into/from the
Column as it's declared as String().
In both cases (True or False), I use "MySQL Query Browser" to visually
control the data in the database. Characters do print correctly without
any funny characters.
countries_table = Table('countries', metadata,
Column('id_country', String(2),
primary_key=True),
Column('name', String(44), nullable=False))
class Country(object):
def __init__(self, id_country, name):
self.id_country = id_country
self.name = name
country_mapper = mapper(Country, countries_table,
order_by=countries_table.c.name)
> are you using MySQL ?
Yes.
The country file used is the following (need to remove 2 first lines):
http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-fr1-semic.txt
SA creates the table that way:
CREATE TABLE countries (
id_country VARCHAR(2) NOT NULL,
name VARCHAR(44) NOT NULL,
PRIMARY KEY (id_country)
)
Then inserts data, looping over the country file:
2006-10-24 12:53:46,102 INFO sqlalchemy.engine.base.Engine.0x..d0 BEGIN
[... some countries ...]
2006-10-24 12:53:46,179 INFO sqlalchemy.engine.base.Engine.0x..d0 INSERT
INTO countries (id_country, name) VALUES (%s, %s)
2006-10-24 12:53:46,179 INFO sqlalchemy.engine.base.Engine.0x..d0 ['AX',
'\xc5LAND, \xceLES']
[... some more countries ...]
2006-10-24 12:53:46,555 INFO sqlalchemy.engine.base.Engine.0x..d0 COMMIT
then reads data back:
2006-10-24 12:53:46,594 INFO sqlalchemy.engine.base.Engine.0x..d0 SELECT
countries.name AS countries_name, countries.id_country AS
countries_id_country
print repr(country.name), type(country.name)
'\xc5LAND, \xceLES' <type 'str'>
All this seems to be working fine. I can't reproduce the initial error
when in the Pylons environement. I guess my problem comes from
Pylons/Myghty. There's another Myghty-level where strings might be
converted as well and where it can blow things up, as you said. I need
to investigate more with that.
Maybe you have any other adivses to make further testing to make sure
it's not an SA problem. When I'm sure about that, I'll stop bothering
this list and start investigating on Myghty's side.
Thank you very much for the help.
Regards,
--
Alexandre CONRAD
>
>
> On Oct 23, 2006, at 2:31 PM, Alexandre CONRAD wrote:
>
>
>>Hello,
>>
>>I seem to have a unicode issue since I updated to 0.3. I'm using
>>Pylons
>>(with Myghty templates), and I have problems reading unicode data
>>from a DB.
>>
>>When my engine is set as "convert_unicode=True", I seem to get an
>>SA error:
>>
>>[...]
>>Module sqlalchemy.types:175 in convert_result_value
>>Module encodings.utf_8:16 in decode
>> errors 'strict'
>> input '\xc5LAND ISLANDS'
>>return codecs.utf_8_decode(input, errors, True)
>>exceptions.UnicodeDecodeError: 'utf8' codec can't decode bytes in
>>position 0-1: invalid data
>>
>>All my Columns() are String().
>>
>>When I set "convert_unicode=False", I seem to have a Myghty write
>>error.
>>
>>Error(UnicodeDecodeError): 'ascii' codec can't decode byte 0xc5 in
>>position 0: ordinal not in range(128)
>>
>>I don't seem to have problems inserting the data in the DB.
>>
>>I had this problem before using 0.2.8, but putting
>>"convert_unicode=True" to my engine() fixed the problem.
>>
>>Any idea ?
>>
>>Regards,
>>--
>>Alexandre CONRAD - TLV FRANCE
>>Research & Development
>>
>>
>
>
> >
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" 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/sqlalchemy
-~----------~----~----~----~------~----~------~--~---