Re: revisit 'Right' way to delete rows from a view in python?
Gordon McMillan <[email protected]>
| Newsgroups | gmane.comp.db.metakit |
|---|---|
| Message-ID | <[email protected]> |
On Tuesday 04 May 2004 03:38 pm, William K. Volkman wrote:
> db = metakit.storage('/var/tmp/test.mk',1)
> vw = db.getas('test[f1:I,f2:s,seq:I,state:s]')
> for i in xrange(5):
> vw.append((i,'%d'%i,99,'F'))
> num = random.randint(0,4)
> if num > 0:
> for s in range(num):
> vw.append((i,'%d'%i,s,'%d'%s))
> db.commit()
> metakit.dump(vw)
>
> pickon = random.randint(0,4)
> print "******** Entry to pick on",pickon
>
> subvw = vw.select(f1=pickon)
> rs = subvw.filter(lambda row: row.state == 'F')
Why filter the selected view? Now you've got the indices in the selected view,
and getting the true indices in the original view takes something like this:
iv1 = vw.indices(subvw)
iv2 = iv1.remapwith(rs)
vw.remove(iv2)
Why not
dead = vw.filter(lambda row: row.f1==pickon and row.state == 'F')
vw.remove(dead)
> subsubvw = subvw.remapwith(rs)
> metakit.dump(subsubvw)
> #
> ## Now I want remove the filter rows, how can I back track?
> #
> ## If I use
> ##vw.remove(rs)
> ## It only works if order is perfect
> #
> ## The delete and remove methods are not available on the derived views
> ##subvw.remove(rs)
> ##subsubvw.remove(rs)
> #
> vw.remove(vw.indices(subvw))
> # Deletes all 'pickon' records, not just the ones in state 'F'
-- Gordon
_____________________________________________
Metakit mailing list - [email protected]
http://www.equi4.com/mailman/listinfo/metakit