On Wed, Feb 6, 2013 at 2:05 AM, Jonathan Vanasco <jonat...@findmeon.com> wrote:
> I use SqlAlchemy in a Pyramid app.  All my models, connections, etc
> are within and set up by Pyramid.
>
> I'm trying to do a maintenance script, and am a bit confused.
>
> In my script, thanks to a bootstraped commandline Pyramid feature, i
> have a Session which can query objects.  great.
>
>      results = dbSession.query( model.core.Useraccount )\
>         .filter(\
>             model.core.Useraccount.last_login.op("IS")(None)
>         )\
>         .all()
>
> here's my problem.  i want to do execute a command like this:
>
>
>      stmt =   model.core.Useraccount.update()\
>             .where( model.core.Useraccount.id.in_( list_of_uids ) )\
>             .values( last_login = 'now()' )
>     connection.execute(stmt)
>
> I'm not actually updating the last_login field. just using this as an
> example.
>
> So here are my questions:
>
> 1. can i get the connection out of a scoped session ?
> 2. i'm getting an error that Useraccount doesn't have an 'update'
> method.
>
> i based the example above on this
> http://docs.sqlalchemy.org/en/rel_0_8/core/tutorial.html#correlated-updates
>
> I think this is all based on a portion of SqlAlchemy that my
> environment doesn't have access to (in that everything is set up for
> scoped sessions, not sql expressions). If so, is there another way to
> execute an update query ?
>

The Session has "connection()" and "execute()" methods which will
probably do what you want:

http://docs.sqlalchemy.org/en/rel_0_8/orm/session.html#using-sql-expressions-with-sessions

Hope that helps,

Simon

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to