- 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
- Internally uses set instead of lists to describe relation's content
- 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
- 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
default format) setting to false the 2nd parameter.
The old format is no longer supported.'''
self._readonly=False
if len(filename)==0:#Empty relation
self.content=set()
self.header=header([])
@ -50,7 +53,14 @@ class relation (object):
#Closing file
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):
'''Saves the relation in a file. By default will save using the csv
format as defined in RFC4180, but setting comma_separated to False,
@ -176,7 +186,8 @@ class relation (object):
return None
#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
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
will be converted into a string.
Returns the number of affected rows.'''
self._make_writable()
affected=0
attributes={}
keys=dic.keys() #List of headers to modify
@ -459,6 +471,8 @@ class relation (object):
if len(self.header.attributes) != len(values):
return 0
self._make_writable()
#Creating list containing only strings
t=[]
for i in values:
@ -474,6 +488,7 @@ class relation (object):
This operation will change the relation itself instead of generating a new one,
deleting all the tuples that make expr true.
Returns the number of affected rows.'''
self._make_writable()
attributes={}
affected=len(self.content)
new_content=set() #New content of the relation

@ -101,7 +101,7 @@ def load_relation(filename,defname=None):
f=filename.split('/')
if defname==None:
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]
try:
@ -287,6 +287,5 @@ def main(files=[]):
sys.exit(0)
if __name__ == "__main__":
main()