3 messages in com.googlegroups.sqlalchemy[sqlalchemy] Re: Session().execute(.....| From | Sent On | Attachments |
|---|---|---|
| jerryji | 25 Dec 2007 11:53 | |
| Michael Bayer | 26 Dec 2007 06:55 | |
| jerryji | 26 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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to sqla...@googlegroups.com
To unsubscribe from this group, send email to
sqla...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---




