On 12/12/06, Stefan Meretz <[EMAIL PROTECTED]> wrote:
> using MySQL in an entirely utf8-environment I got the following:
>
> class Testtable(ActiveMapper):
> class mapping:
> pkey = column(Unicode(10), primary_key=True)
> test = column(Unicode(4))
>
> sqlalchemy.dburi="mysql://test:[EMAIL PROTECTED]/testdb?use_unicode=1"
>
> MySQLdb.__version__
> 1.2.1_p2
>
> >>> t = Testtable.selectone()
> >>> t.test
> u's\xfcd'
> >>> print t.test
> süd
> >>> s = t.test
> >>> s = s + '!'
> >>> print s
> süd!
> >>> t.test = s
> >>> session.flush()
> 2006-12-12 16:07:36,684 INFO sqlalchemy.engine.base.Engine.0x..b4 BEGIN
> 2006-12-12 16:07:36,684 sqlalchemy.engine.base.Engine.0x..b4 INFO BEGIN
> 2006-12-12 16:07:36,686 INFO sqlalchemy.engine.base.Engine.0x..b4 UPDATE
> testtable SET test=%s WHERE testtable.pkey = %s
> 2006-12-12 16:07:36,686 sqlalchemy.engine.base.Engine.0x..b4 INFO UPDATE
> testtable SET test=%s WHERE testtable.pkey = %s
> 2006-12-12 16:07:36,687 INFO sqlalchemy.engine.base.Engine.0x..b4
> ['s\xc3\xbcd!', 'first']
> 2006-12-12 16:07:36,687 sqlalchemy.engine.base.Engine.0x..b4 INFO
> ['s\xc3\xbcd!', 'first']
> /usr/lib/python2.4/site-packages/SQLAlchemy-0.3.1-py2.4.egg/sqlalchemy/engine/default.py:64:
> Warning: Data truncated for column 'test' at row 1
> 2006-12-12 16:07:36,692 INFO sqlalchemy.engine.base.Engine.0x..b4 COMMIT
> 2006-12-12 16:07:36,692 sqlalchemy.engine.base.Engine.0x..b4 INFO COMMIT
>
> >>> s
> u's\xfcd!'
>
> However, this is used by SA during update:
> >>> s.encode('utf8')
> 's\xc3\xbcd!'
>
> Is this "double encoding" due to "use_unicode=1" on SQLAlchemy, or is it
> a MySQLdb problem? Or any problem between my ears??
>
> When I do it on pure MySQLdb, everything works fine. Not surprisingly,
> because I explicitly say:
>
> cursor.execute("update testtable set test=%s", s)
>
> having s as given above (only one row, no where-clause needed).
Have you read this thread:
http://www.mail-archive.com/[email protected]/msg00366.html
Best Regards,
-jj
--
http://jjinux.blogspot.com/
--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---