added selection
git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@6 014f5005-505e-4b48-8d0a-63407b615a7c
This commit is contained in:
parent
7817d6adaf
commit
7d048cb399
19
relation.py
19
relation.py
@ -54,7 +54,24 @@ class relation (object):
|
|||||||
fp=file(filename,'w')
|
fp=file(filename,'w')
|
||||||
fp.write(res)
|
fp.write(res)
|
||||||
fp.close()
|
fp.close()
|
||||||
|
def selection(self,expr):
|
||||||
|
'''Selection, expr must be a valid boolean expression, can contain field names,
|
||||||
|
constant, math operations and boolean ones.'''
|
||||||
|
fields={}
|
||||||
|
newt=relation()
|
||||||
|
newt.header=header(list(self.header.fields))
|
||||||
|
for i in self.content:
|
||||||
|
for j in range(len(self.header.fields)):
|
||||||
|
if i[j].isdigit():
|
||||||
|
fields[self.header.fields[j]]=int(i[j])
|
||||||
|
else:
|
||||||
|
fields[self.header.fields[j]]=i[j]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if eval(expr,fields):
|
||||||
|
newt.content.append(i)
|
||||||
|
return newt
|
||||||
def product (self,other):
|
def product (self,other):
|
||||||
'''Cartesian product, fields must be different to avoid collisions
|
'''Cartesian product, fields must be different to avoid collisions
|
||||||
Doing this operation on relations with colliding fields will
|
Doing this operation on relations with colliding fields will
|
||||||
|
9
samples/people.tlb
Normal file
9
samples/people.tlb
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
id name chief age
|
||||||
|
0 jack 0 22
|
||||||
|
1 carl 0 20
|
||||||
|
2 john 1 30
|
||||||
|
3 dean 1 33
|
||||||
|
4 eve 0 25
|
||||||
|
5 duncan 4 30
|
||||||
|
6 paul 4 30
|
||||||
|
7 alia 1 28
|
Loading…
x
Reference in New Issue
Block a user