- Rename will mark the resulting relation as readonly and subsequent updates, insert or deletes will actually copy the content

git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@251 014f5005-505e-4b48-8d0a-63407b615a7c
master
LtWorf 2010-09-22 13:12:02 +07:00
parent 2073b4db4a
commit d63d0e78c0
3 changed files with 19 additions and 4 deletions

@ -3,6 +3,7 @@
- Added manpage for relational-cli - Added manpage for relational-cli
- Internally uses set instead of lists to describe relation's content - Internally uses set instead of lists to describe relation's content
- Discards the old and not so functional tlb format - Discards the old and not so functional tlb format
- Rename will mark the resulting relation as readonly and subsequent updates, insert or deletes will actually copy the content
0.11 0.11
- Font is set only on windows (Rev 206) - Font is set only on windows (Rev 206)

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

@ -101,7 +101,7 @@ def load_relation(filename,defname=None):
f=filename.split('/') f=filename.split('/')
if defname==None: if defname==None:
defname=f[len(f)-1].lower() defname=f[len(f)-1].lower()
if (defname.endswith(".csv") or defname.endswith(".tlb")): #removes the extension if defname.endswith(".csv"): #removes the extension
defname=defname[:-4] defname=defname[:-4]
try: try:
@ -287,6 +287,5 @@ def main(files=[]):
sys.exit(0) sys.exit(0)
if __name__ == "__main__": if __name__ == "__main__":
main() main()