On 11/7/06, Shannon -jj Behrens <[EMAIL PROTECTED]> wrote:
> The following results in correct data going into and coming out of the
> database, but the data in the database itself looks double encoded:
>
> import MySQLdb
>
>
> connection = MySQLdb.connect(host="fmapp03", user="foxmarks",
>                              passwd='ChunkyBacon', db="users")
> cursor = connection.cursor()
> cursor.execute("""
>     INSERT INTO users
>     VALUES (12345678, 'jjtest1234', '[EMAIL PROTECTED]', 'pass', %s,
>             'asdf', 'N/A', 'N/A', 0, NOW(), NOW())
> """, ('\xc3\xa7',))
> cursor.execute("SELECT * FROM users WHERE id = 12345678")
> row = cursor.fetchone()
> print `row`
> connection.commit()
>
> The following results in correct data going into and out of the
> database, but does not result in the data in the database itself being
> double encoded:
>
> import MySQLdb
>
>
> connection = MySQLdb.connect(host="fmapp03", user="foxmarks",
>                              passwd='ChunkyBacon', db="users",
>                              charset='utf8')
> cursor = connection.cursor()
> cursor.execute("""
>     INSERT INTO users
>     VALUES (12345678, 'jjtest1234', '[EMAIL PROTECTED]', 'pass', %s,
>             'asdf', 'N/A', 'N/A', 0, NOW(), NOW())
> """, (u'\xe7',))
> cursor.execute("SELECT * FROM users WHERE id = 12345678")
> row = cursor.fetchone()
> print `row`
> connection.commit()
>
> It looks like for the version of MySQLdb I'm using, 1.2.1p2, a lot of
> this stuff has changed. If you don't let MySQLdb take care of encoding
> and decoding, it ends up double encoding things in the database. This
> must be a bug in MySQLdb. The clear way to work around the bug is to
> let the driver take care of encoding and decoding instead of
> SQLAlchemy.
>
> Yuck,
> -jj

BTW, it also turned out that I needed to run the version of SQLAlchemy
from trunk.  Otherwise, this setup results in the following exception:

  File 
"/usr/lib/python2.4/site-packages/PasteScript-1.0-py2.4.egg/paste/script/serve.py",
line 184, in command
    relative_to=base)
  File 
"/usr/lib/python2.4/site-packages/PasteScript-1.0-py2.4.egg/paste/script/serve.py",
line 204, in loadapp
    return loadapp(app_spec, name=name, relative_to=relative_to)
  File 
"/usr/lib/python2.4/site-packages/PasteDeploy-1.0-py2.4.egg/paste/deploy/loadwsgi.py",
line 193, in loadapp
    return loadobj(APP, uri, name=name, **kw)
  File 
"/usr/lib/python2.4/site-packages/PasteDeploy-1.0-py2.4.egg/paste/deploy/loadwsgi.py",
line 214, in loadobj
    return context.create()
  File 
"/usr/lib/python2.4/site-packages/PasteDeploy-1.0-py2.4.egg/paste/deploy/loadwsgi.py",
line 596, in create
    return self.object_type.invoke(self)
  File 
"/usr/lib/python2.4/site-packages/PasteDeploy-1.0-py2.4.egg/paste/deploy/loadwsgi.py",
line 99, in invoke
    return fix_call(context.object, context.global_conf, **context.local_conf)
  File 
"/usr/lib/python2.4/site-packages/PasteDeploy-1.0-py2.4.egg/paste/deploy/util/fixtypeerror.py",
line 57, in fix_call
    val = callable(*args, **kw)
  File 
"/usr/lib/python2.4/site-packages/acctmgr-0.0.0dev_r529-py2.4.egg/acctmgr/config/middleware.py",
line 36, in make_app
    g=app_globals.Globals)
  File 
"/usr/lib/python2.4/site-packages/Pylons-0.9.3-py2.4.egg/pylons/wsgiapp.py",
line 302, in __init__
    g = g(config.global_conf, config.app_conf, config=config)
  File 
"/usr/lib/python2.4/site-packages/acctmgr-0.0.0dev_r529-py2.4.egg/acctmgr/lib/app_globals.py",
line 34, in __init__
    init_model(app_conf)
  File 
"/usr/lib/python2.4/site-packages/acctmgr-0.0.0dev_r529-py2.4.egg/acctmgr/models/__init__.py",
line 39, in init_model
    users_table = Table('users', metadata, autoload=True)
  File "build/bdist.linux-i686/egg/sqlalchemy/schema.py", line 138, in __call__
  File "build/bdist.linux-i686/egg/sqlalchemy/engine/base.py", line
491, in reflecttable
  File "build/bdist.linux-i686/egg/sqlalchemy/databases/mysql.py", line 358, in
reflecttable
TypeError: __init__() keywords must be strings

Debugging produced:

args: [20]
kargs: {u'unsigned': True}

Anyway, it's fixed on trunk.

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 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