Relation module has SQL-like delete

git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@75 014f5005-505e-4b48-8d0a-63407b615a7c
This commit is contained in:
LtWorf 2008-12-25 11:26:40 +00:00
parent d59ba9f9f1
commit 1b09369198
2 changed files with 22 additions and 0 deletions

View File

@ -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

View File

@ -418,6 +418,27 @@ class relation (object):
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.
It is used within relations to know if requested operations are accepted'''