On Jul 20, 2010, at 6:19 PM, Lukasz Szybalski wrote: > > > On Jul 20, 4:55 pm, Michael Bayer <mike...@zzzcomputing.com> wrote: >> On Jul 20, 2010, at 5:10 PM, Lukasz Szybalski wrote: >> >> >> >> >> >>> On Jul 20, 3:46 pm, Michael Bayer <mike...@zzzcomputing.com> wrote: >>>> On Jul 20, 2010, at 4:44 PM, Lukasz Szybalski wrote: >> >>>>>> Session.execute() accepts strings that are converted to text(): >> >>>>>> a=session.execute("assp_ReportDailyTransactions >>>>>> @start_date=:start,@end_date=:end", >>>>>> params={'start':"20100701",'end':"20100719"}) >> >>>>> Thanks, >>>>> That does work. >> >>>>> Is it possible to get each record to be returned as object instead of >>>>> dictionary or change it so that it is similar object >>>>> as ..session.query(....).all()? >> >>>> sure, query.from_statement(), its in the ORM tutorial.... >> >>> Sorry, I think I'm reading it wrong. >> >>> a=session.query().from_statement("assp_ReportDailyTransactions >>> @start_date=:start, >>> @end_date=:end").params(start="20100701",end="20100719").all() >> >> query() needs to have entities. Here's an example: >> >> http://www.sqlalchemy.org/docs/ormtutorial.html#using-literal-sql >> > > Can I pass in a list or some other type, I have over 30 columns?
Its not clear what you are asking for. execute().fetchall() already returns a list of rows, where each row has attributes, so that you can say "row.attrname", so it is already like "an object". If you use a query(), you have the choice of specifying an ORM mapped class or individual columns as well, though if you are querying for all individual columns there's not much difference between query(x, y, z).all() versus using execute().fetchall(). When you say "change it", if that means, "I'd like to set attributes on the resulting objects and they go back to the database", that's clearly not possible unless you can relate your stored procedure rows to an ORM mapped class, since SQLAlchemy knows nothing about how your stored procedure gets data or how that data would be modified. If you can illustrate fully what kind of interface to the data you'd like to see that be helpful. > > a=session.execute("assp_ReportDailyTransactions @start_date=:start, > @end_date=:end",params={'start':"20100701",'end':"20100719"}) > > b=session.query(a.keys()).from_statement("exec > assp_ReportDailyTransactions @start_date=:start, > @end_date=:end").params({'start':"20100701",'end':"20100719"}).all() > > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File "/home/lucas/tmp/sql2008/env/lib/python2.5/site-packages/ > SQLAlchemy-0.6.3-py2.5.egg/sqlalchemy/orm/session.py", line 873, in > query > return self._query_cls(entities, self, **kwargs) > File "/home/lucas/tmp/sql2008/env/lib/python2.5/site-packages/ > SQLAlchemy-0.6.3-py2.5.egg/sqlalchemy/orm/query.py", line 92, in > __init__ > self._set_entities(entities) > File "/home/lucas/tmp/sql2008/env/lib/python2.5/site-packages/ > SQLAlchemy-0.6.3-py2.5.egg/sqlalchemy/orm/query.py", line 99, in > _set_entities > entity_wrapper(self, ent) > File "/home/lucas/tmp/sql2008/env/lib/python2.5/site-packages/ > SQLAlchemy-0.6.3-py2.5.egg/sqlalchemy/orm/query.py", line 2584, in > __init__ > "expected - got '%r'" % column > sqlalchemy.exc.InvalidRequestError: SQL expression, column, or mapped > entity expected - got '[u'customer', u'customer_id', u'customer_num', > u'TransactionDate'......] > > > Thanks, > Lucas > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalch...@googlegroups.com. > To unsubscribe from this group, send email to > sqlalchemy+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.