From 1b093691985ce0be0bcf0541bdd3b5ecb30887ce Mon Sep 17 00:00:00 2001 From: LtWorf Date: Thu, 25 Dec 2008 11:26:40 +0000 Subject: [PATCH] Relation module has SQL-like delete git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@75 014f5005-505e-4b48-8d0a-63407b615a7c --- CHANGELOG | 1 + relation.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 6cda88a..e82223a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -51,3 +51,4 @@ - New default relation's format is csv, as defined in RFC4180 - Converted sample's relations to csv - Deb postinstall generates optimized files, this will increase loading speed +- Relation module has SQL-like delete diff --git a/relation.py b/relation.py index 199a3f0..8224f2a 100644 --- a/relation.py +++ b/relation.py @@ -417,6 +417,27 @@ class relation (object): col+=1 return res + + def delete(self,expr): + '''Delete, expr must be a valid boolean expression, can contain field names, + constant, math operations and boolean ones. + This operation will change the relation itself instead of generating a new one, + deleting all the touples that make expr true.''' + attributes={} + new_content=[] #New content of the relation + for i in self.content: + for j in range(len(self.header.attributes)): + if i[j].isdigit(): + attributes[self.header.attributes[j]]=int(i[j]) + elif rstring(i[j]).isFloat(): + attributes[self.header.attributes[j]]=float(i[j]) + elif isDate(i[j]): + attributes[self.header.attributes[j]]=rdate(i[j]) + else: + attributes[self.header.attributes[j]]=i[j] + if not eval(expr,attributes): + new_content.append(i) + self.content=new_content class header (object): '''This class defines the header of a relation.