"cities = cities.select(limit=1).execute().fetchall()" works well with
this configuration, but leads to error in "nregion =
places.select(places.c.name == iv2).execute()"

if "nregion = places.select(places.c.name == iv2).execute()" used
first, then string conversion error appear at "cities =
cities.select(limit=1).execute().fetchall()"

Probably, MySQL charset setting is library-wide, but not connection-
wide.


On Feb 2, 1:44 am, "Michael Bayer" <[EMAIL PROTECTED]> wrote:
> dont use the Unicode type if your MySQL client and/or server is
> converting unicode for you.  "convert_unicode=False" has no effect on
> the Unicode type.
>
> also note theres a bug in MySQLDB related to this:
>
> http://sourceforge.net/tracker/index.php?func=detail&aid=1592353&grou...http://www.sqlalchemy.org/trac/ticket/340
>
> On Feb 1, 7:28 am, "Andrew Stromnov" <[EMAIL PROTECTED]> wrote:
>
> > Python 2.4.4 (win32) + SQLAlchemy (r2285) + MySQLdb 1.2.1
>
> > Code:
>
> > from sqlalchemy import create_engine, BoundMetaData
> > from sqlalchemy import Table, Column, Integer, String, SmallInteger,
> > Unicode
>
> > dburl1 = 'mysql://login:[EMAIL PROTECTED]/geobase?
> > use_unicode=1&charset=cp1251&compress=1'
> > engine1 = create_engine(dburl1, echo=False)
> > metadata1 = BoundMetaData(engine1)
> > cities = Table('cities', metadata1,
> >     Column('id', Integer, autoincrement=True, primary_key=True),
> >     Column('region_id', Integer, nullable=False, default=0),
> >     Column('country_id', Integer, nullable=False, default=0),
> >     Column('dialcode', String(7), nullable=False, default=''),
> >     Column('name', String(64), nullable=False, default=''),
> >     Column('mask', String(5), nullable=False, default=''),
> >     Column('metro', SmallInteger, nullable=False, default='0') )
>
> > dburl2 = 'mysql://login:[EMAIL PROTECTED]/geobase?
> > use_unicode=1&charset=utf8'
> > engine2 = create_engine(dburl2, echo=False, convert_unicode=False)
> > metadata2 = BoundMetaData(engine2)
>
> > places = Table('places', metadata2,
> >     Column('id', Integer, autoincrement=True, primary_key=True),
> >     Column('name', Unicode(64), nullable=False, default=''),
> >     Column('parent', Integer, nullable=False, default=0),
> >     Column('left', Integer, nullable=False, default=0),
> >     Column('right', Integer, nullable=False, default=0),
> >     Column('depth', Integer, nullable=False, default=0),
> >     Column('type', Integer, nullable=False, default=0),
> >     Column('dialcode', Unicode(7), nullable=True),
> >     Column('mask', Unicode(5), nullable=True),
> >     Column('code', Integer, nullable=True),
> >     Column('domain', Unicode(5), nullable=True),
> >     )
>
> > # BLOCK
> > cities = cities.select(limit=1).execute().fetchall()
> > # BLOCK
>
> > iv2 = u'\u0418\u0432\u0430\u043d\u043e\u0432\u0441\u043a\u0430\u044f
> > \u043e\u0431\u043b.'
> > nregion = places.select(places.c.name == iv2).execute()
>
> > ----
>
> > Traceback (most recent call last):
> >   File "e.py", line 37, in ?
> >     nregion = places.select(places.c.name == iv2).execute()
> >   File "\Python24\Lib\site-packages\sqlalchemy\sql.py", line 476, in
> > execute
> >   File "\Python24\Lib\site-packages\sqlalchemy\sql.py", line 414, in
> > execute
> >   File "C:\Python24\lib\site-packages\sqlalchemy\engine\base.py", line
> > 492, in execute_compiled
> >     return connection.execute_compiled(compiled, *multiparams,
> > **params)
> >   File "C:\Python24\lib\site-packages\sqlalchemy\engine\base.py", line
> > 303, in execute_compiled
> >     proxy(str(compiled), parameters)
> >   File "C:\Python24\lib\site-packages\sqlalchemy\engine\base.py", line
> > 299, in proxy
> >     self._execute_raw(statement, parameters, cursor=cursor,
> > context=context)
> >   File "C:\Python24\lib\site-packages\sqlalchemy\engine\base.py", line
> > 337, in _execute_raw
> >     self._execute(cursor, statement, parameters, context=context)
> >   File "C:\Python24\lib\site-packages\sqlalchemy\engine\base.py", line
> > 356, in _execute
> >     raise exceptions.SQLError(statement, parameters, e)
> > sqlalchemy.exceptions.SQLError: (UnicodeDecodeError) 'charmap' codec
> > can't decode byte 0x98 in position 1: character maps to <undefined>
> > 'SELECT places.id, places.name, places.parent, places.`left`,
> > places.`right`, places.depth, places.type, places.dialcode,
> > places.mask, places.code, places.domain \nFROM places \nWHERE
> > places.name = %s' ['\xd0\x98\xd0\xb2\xd0\xb0\xd0\xbd\xd0\xbe
> > \xd0\xb2\xd1\x81\xd0\xba\xd0\xb0\xd1\x8f \xd0\xbe\xd0\xb1\xd0\xbb.']


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to