im not able to reproduce this problem, i can send unicode() into get_by or SQL constructs directly no problem. i also dont immediately see anything that could cause it to construe a unicode string as anything other than a literal value (unless the unicode() function on your end is being clobered by something?) can you attach a fully working test case ?

On May 8, 2006, at 10:59 AM, Dennis Muhlestein wrote:

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



-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to