On Jul 20, 6:02 pm, Michael Bayer <mike...@zzzcomputing.com> wrote: > 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. > >
Sorry for not being clear. Instead of typing manually column names ("column1","column2",..."column38" inside the query() I would like to use previous query .keys() to list them there.... Instead doing: myresults=session.query('column1','column2','column3').from_statement.... I would like to do a=session.execute(...) and then myresults=session.query(a.keys()).from_statement(....) where a.keys() returns a list of all the column names from the stored procedure, but unfortunately passing a list like "a.keys()" gives me an error. If I type it in it works fine. How can I pass in these column names ? Should I convert a.keys() to dictionary, or some other type? __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'......] I tried fetchall but when I loop over the rows, I was getting a dictionary and instead of doing row.column1, I had to use row[0]. 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.