Piotr Kęplicz pisze:
> Joe Riopel, środa 07 stycznia 2009 17:45:
>
>>> Session.query(Person).filter_by(...).delete()
>>>
>> Isn't that code still doing the select first, to get the object, and
>> then deleting it?
>>
>
> No. It's a Query object turned into a DELETE statement, just like first(),
> all() or one() would turn it into a SELECT statement.
>
pylons 0.9.7, sqlalchemy 0.5
This is copy paste from console:
Pylons Interactive Shell
Python 2.5 (release25-maint, Jul 20 2008, 20:47:25)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)]
All objects from pyupo.lib.base are available
Additional Objects:
mapper - Routes mapper object
wsgiapp - This project's WSGI App instance
app - paste.fixture wrapped around wsgiapp
>>> from pyupo.model.meta import Session
>>> from pyupo.model.emailbag import EmailBag as e
>>> s = Session.query(e).filter(e.order_id == 1).filter(e.active ==
True).filter(e.dispatched == False)
>>> s.delete()
07:10:35,545 INFO [sqlalchemy.engine.base.Engine.0x...6acL] BEGIN
07:10:35,546 INFO [sqlalchemy.engine.base.Engine.0x...6acL] SELECT em
ailbag.id AS emailbag_id
FROM emailbag
WHERE emailbag.order_id = %s AND emailbag.active = %s AND emailbag.dis
patched = %s
07:10:35,546 INFO [sqlalchemy.engine.base.Engine.0x...6acL] [1, 1, 0]
07:10:35,547 DEBUG [sqlalchemy.engine.base.Engine.0x...6acL] Col
('emailbag_id',)
07:10:35,547 INFO [sqlalchemy.engine.base.Engine.0x...6acL] DELETE FROM
emailbag WHERE emailbag.order_id = %s AND emailbag.active = %s AND
emailbag.dispatched = %s
07:10:35,547 INFO [sqlalchemy.engine.base.Engine.0x...6acL] [1, 1, 0]
0L
>>> s.update({'active': False})
07:12:15,965 INFO [sqlalchemy.engine.base.Engine.0x...6acL] SELECT
emailbag.id AS emailbag_id FROM emailbag
WHERE emailbag.order_id = %s AND emailbag.active = %s AND
emailbag.dispatched = %s
07:12:15,965 INFO [sqlalchemy.engine.base.Engine.0x...6acL] [1, 1, 0]
07:12:15,965 DEBUG [sqlalchemy.engine.base.Engine.0x...6acL] Col
('emailbag_id',)
07:12:15,966 INFO [sqlalchemy.engine.base.Engine.0x...6acL] UPDATE
emailbag SET active=%s, updated_at=CURRENT_DATE WHERE emailbag.order_id
= %s AND emailbag.active = %s AND emailbag.dispatched = %s
07:12:15,966 INFO [sqlalchemy.engine.base.Engine.0x...6acL] [0, 1, 1, 0]
0L
This examples say something else.
What is wrong with this query?
Best Regards,
Tomek
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---