I'm having a small problem with parameters on my select queries. If the parameter is unicode instead of a string, the select throws an exception
Example OK:
>p=Profile.get_by(username='dennis')
>p.username
'dennis'
Example Broken:
>p=Profile.get_by(username=unicode('dennis'))
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "build/bdist.linux-i686/egg/sqlalchemy/mapping/mapper.py", line 258, in get_by
File "build/bdist.linux-i686/egg/sqlalchemy/mapping/query.py", line 58, in get_by
File "build/bdist.linux-i686/egg/sqlalchemy/mapping/query.py", line 137, in select_whereclause
File "build/bdist.linux-i686/egg/sqlalchemy/mapping/query.py", line 213, in _select_statement
File "build/bdist.linux-i686/egg/sqlalchemy/sql.py", line 473, in execute
File "build/bdist.linux-i686/egg/sqlalchemy/sql.py", line 378, in execute
File "build/bdist.linux-i686/egg/sqlalchemy/sql.py", line 355, in execute
File "build/bdist.linux-i686/egg/sqlalchemy/engine.py", line 646, in execute_compiled
File "build/bdist.linux-i686/egg/sqlalchemy/engine.py", line 641, in proxy
File "build/bdist.linux-i686/egg/sqlalchemy/engine.py", line 692, in execute
File "build/bdist.linux-i686/egg/sqlalchemy/engine.py", line 712, in _execute
sqlalchemy.exceptions.SQLError: (ProgrammingError) ERROR: column "dennis" does not exist
(This occurs when I use the select function as well as mapped objects.) The sql causing the error is because the value of the parameter username does not have quotes around it when the value is in unicode. ( "WHERE
profile.username = dennis " instead of "WHERE profile.username = 'dennis' ")
I started having this exception when I upgraded Turbogears. It appears they made a change that converts parameters to unicode objects. It also appears SQLAlchemy doesn't treat unicode objects the same way it treats strings. I'm not sure that it should necessarily, or that anything is broken, but I thought I'd see if anyone has any thoughts. For the time being, I've cast my bind parameters to strings and it's working again.
Thanks
Dennis
- [Sqlalchemy-users] unicode parameters Dennis Muhlestein
- Re: [Sqlalchemy-users] unicode parameters Michael Bayer
- Re: [Sqlalchemy-users] unicode parameters Dennis Muhlestein
- Re: [Sqlalchemy-users] unicode parameters Sean Cazzell
- Re[2]: [Sqlalchemy-users] unicode param... Gambit
- Re: [Sqlalchemy-users] unicode par... Randall Smith
- Re: [Sqlalchemy-users] unicode... Michael Bayer
- Re: [Sqlalchemy-users] uni... Randall Smith
- Re: [Sqlalchemy-users] uni... Randall Smith