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:
parent
d59ba9f9f1
commit
1b09369198
@ -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
|
||||
|
21
relation.py
21
relation.py
@ -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'''
|
||||
|
Loading…
x
Reference in New Issue
Block a user