diff --git a/CHANGELOG b/CHANGELOG index 9653f61..a371186 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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) diff --git a/relational/relation.py b/relational/relation.py index 2458f90..d623ff9 100644 --- a/relational/relation.py +++ b/relational/relation.py @@ -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 diff --git a/relational_readline/linegui.py b/relational_readline/linegui.py index 979d898..9258a37 100644 --- a/relational_readline/linegui.py +++ b/relational_readline/linegui.py @@ -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() \ No newline at end of file