Re: [SQLObject] Re: Question about multiple deletes
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Ian B. <ia...@co...> - 2004-02-19 22:11:03
|
Chris Gahan wrote: > "David McNab" <da...@re...> wrote in message > news:402...@re...... > >>What's the best way, within SQLObject, to delete an entire results set >>from a table? >> >>In other words, the equivalent of an SQL query like: >> >> DELETE FROM mytable WHERE last_name = 'Jones' AND age > 50 >> >>I know I can iterate through an SQLObject result set and invoke >>.destroySelf() on every element, but this feels painfully inefficient. > > > There's nothing in SQLObject right now that does this, but you could add > your own method pretty easily... > > Just add a function to the SQLObject class called .multiDelete() or > something, which works the same as .select().. (i.e. takes in the same > parameters... obviously it would do something quite different. ;) Oops, guess I missed this message. It's a little more complicated than that, because a delete should really go through the SQLObject instances. Selects should be extended so you can retrieve IDs instead of full objects, then there should be a way to fetch an object only if it already exists in Python. Then you'd iterate over the select results and call destroySelf on any objects that existed, and then do another SQL statement to delete any rows that didn't have Python instances. Ian |