This message did not make it to the list last time, lets see if it work now..
On Sep 29, 2013, at 2:41 PM, Roman Iten <roman.i...@sg-unteraegeri.ch> wrote: > Hi > > I started a pyramid project using the alchemy scaffold (includes > ZopeTransactionExtension to scope sessions to requests, see [1]). > > Trying to insert many 'shots' into a MySQL database with a single SQL > statement, I implemented the following view: > > DBSession = scoped_session( > sessionmaker(extension=ZopeTransactionExtension())) > > @view_config(route_name='upload') > def upload_view(request): > shotlist = [] > shotlist.append(Shot(score=92)) > shotlist.append(Shot(score=82)) > shotlist.append(Shot(score=99)) > shotlist.append(Shot(score=78)) > > # The transaction is only committed if this line is enabled: > # DBSession.add(Shot(score=42)) > > DBSession.execute(Shot.__table__.insert(), > [shot.__dict__ for shot in shotlist]) > > return Response('OK') > > But the transaction is not committed. I discovered that the transaction is > committed only if I call add() on DBSession (all five shots are inserted > then)… That is expected behaviour: zope.sqlalchemy can only detect changes when you use the ORM. If you execute statements directly you need to tell zope.sqlalchemy explicitly that a change was made in the session. This is done via mark_changed: from zope.sqlalchemy import mark_changed mark_changed(DBSession()) For more information see the zope.sqlalchemy documentation at https://pypi.python.org/pypi/zope.sqlalchemy Wichert. -- 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. For more options, visit https://groups.google.com/groups/opt_out.