|
|
@ -33,6 +33,9 @@ class relation (object):
|
|
|
|
RFC4180, but it can also be handled like a space separated file (previous
|
|
|
|
RFC4180, but it can also be handled like a space separated file (previous
|
|
|
|
default format) setting to false the 2nd parameter.
|
|
|
|
default format) setting to false the 2nd parameter.
|
|
|
|
The old format is no longer supported.'''
|
|
|
|
The old format is no longer supported.'''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self._readonly=False
|
|
|
|
|
|
|
|
|
|
|
|
if len(filename)==0:#Empty relation
|
|
|
|
if len(filename)==0:#Empty relation
|
|
|
|
self.content=set()
|
|
|
|
self.content=set()
|
|
|
|
self.header=header([])
|
|
|
|
self.header=header([])
|
|
|
@ -50,6 +53,13 @@ class relation (object):
|
|
|
|
#Closing file
|
|
|
|
#Closing file
|
|
|
|
fp.close()
|
|
|
|
fp.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _make_writable(self):
|
|
|
|
|
|
|
|
'''If this relation is marked as readonly, this
|
|
|
|
|
|
|
|
method will copy the content to make it writable too'''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self._readonly:
|
|
|
|
|
|
|
|
self.content=set(self.content)
|
|
|
|
|
|
|
|
self._readonly=False
|
|
|
|
|
|
|
|
|
|
|
|
def save(self,filename):
|
|
|
|
def save(self,filename):
|
|
|
|
'''Saves the relation in a file. By default will save using the csv
|
|
|
|
'''Saves the relation in a file. By default will save using the csv
|
|
|
@ -176,7 +186,8 @@ class relation (object):
|
|
|
|
return None
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
#TODO only copy the link and mark the new relation as read only
|
|
|
|
#TODO only copy the link and mark the new relation as read only
|
|
|
|
newt.content=set(self.content)
|
|
|
|
newt.content=self.content
|
|
|
|
|
|
|
|
newt._readonly=True
|
|
|
|
return newt
|
|
|
|
return newt
|
|
|
|
|
|
|
|
|
|
|
|
def intersection(self,other):
|
|
|
|
def intersection(self,other):
|
|
|
@ -420,6 +431,7 @@ class relation (object):
|
|
|
|
Dic must be a dictionary that has the form field name:value. Every kind of value
|
|
|
|
Dic must be a dictionary that has the form field name:value. Every kind of value
|
|
|
|
will be converted into a string.
|
|
|
|
will be converted into a string.
|
|
|
|
Returns the number of affected rows.'''
|
|
|
|
Returns the number of affected rows.'''
|
|
|
|
|
|
|
|
self._make_writable()
|
|
|
|
affected=0
|
|
|
|
affected=0
|
|
|
|
attributes={}
|
|
|
|
attributes={}
|
|
|
|
keys=dic.keys() #List of headers to modify
|
|
|
|
keys=dic.keys() #List of headers to modify
|
|
|
@ -459,6 +471,8 @@ class relation (object):
|
|
|
|
if len(self.header.attributes) != len(values):
|
|
|
|
if len(self.header.attributes) != len(values):
|
|
|
|
return 0
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self._make_writable()
|
|
|
|
|
|
|
|
|
|
|
|
#Creating list containing only strings
|
|
|
|
#Creating list containing only strings
|
|
|
|
t=[]
|
|
|
|
t=[]
|
|
|
|
for i in values:
|
|
|
|
for i in values:
|
|
|
@ -474,6 +488,7 @@ class relation (object):
|
|
|
|
This operation will change the relation itself instead of generating a new one,
|
|
|
|
This operation will change the relation itself instead of generating a new one,
|
|
|
|
deleting all the tuples that make expr true.
|
|
|
|
deleting all the tuples that make expr true.
|
|
|
|
Returns the number of affected rows.'''
|
|
|
|
Returns the number of affected rows.'''
|
|
|
|
|
|
|
|
self._make_writable()
|
|
|
|
attributes={}
|
|
|
|
attributes={}
|
|
|
|
affected=len(self.content)
|
|
|
|
affected=len(self.content)
|
|
|
|
new_content=set() #New content of the relation
|
|
|
|
new_content=set() #New content of the relation
|
|
|
|