3 messages in com.googlegroups.sqlalchemy[sqlalchemy] Re: Session().execute(.....
FromSent OnAttachments
jerryji25 Dec 2007 11:53 
Michael Bayer26 Dec 2007 06:55 
jerryji26 Dec 2007 07:04 
Subject:[sqlalchemy] Re: Session().execute(...) with parameter syntax error exception
From:jerryji (jerr@gmail.com)
Date:12/26/2007 07:04:06 AM
List:com.googlegroups.sqlalchemy

Hi Michael,

Thank you very much for the enlightenment.

In this case, I think the SQLAlchemy 0.4 documentation needs a little update: under section "Using SQL Expressions with Sessions" (http:// www.sqlalchemy.org/docs/04/session.html#unitofwork_sql) --

Session = sessionmaker(bind=engine, transactional=True) sess = Session() result = sess.execute("select * from table where id=:id", {'id':7})

Shouldn't the sess.execute(...) line become --

result = sess.execute(text("select * from table where id=:id"), {'id': 7})

Thanks.

Jerry

On Dec 26, 9:56 am, Michael Bayer <mike@zzzcomputing.com> wrote:

On Dec 25, 2007, at 2:54 PM, jerryji wrote:

However, the following parameterized version fails --

result = model.Session.execute("select * from labels where labelid=:labelid", {'labelid':10}, mapper=model.Label)

with the following syntax error exception --

...

heya -

the "generic" textual bind params i.e. ":someparam" apply to the "sql.text()" construct, whereas a plain string doesnt get processed at all, so do it like Session.execute(text("select * from foo where x=:label"), {<params>}, ...).

- mike