From 278036081ff0218eaea082903ea81e9a1b725e94 Mon Sep 17 00:00:00 2001 From: LtWorf Date: Wed, 5 Nov 2008 17:18:28 +0000 Subject: [PATCH] Changed internal rename method. Now uses a dictionary git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@50 014f5005-505e-4b48-8d0a-63407b615a7c --- CHANGELOG | 3 ++- parser.py | 4 ++-- relation.py | 14 +++++++------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 55b8198..eadf0ca 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -38,4 +38,5 @@ 0.7 - Added README - Expressions between quotes aren't parsed anymore -- When adding a relation, the file must be choosen 1st, and then the default relation's name is the same as the filename \ No newline at end of file +- When adding a relation, the file must be choosen 1st, and then the default relation's name is the same as the filename +- Changed internal rename method. Now uses a dictionary \ No newline at end of file diff --git a/parser.py b/parser.py index 7e2f11b..0e163e9 100644 --- a/parser.py +++ b/parser.py @@ -106,8 +106,8 @@ def parse(expr): res="%s.selection(\"%s\")" % (internal,parameters) expr= ("%s%s%s") % (expr[0:start-2],res,expr[end+1:]) elif symbol=="ρ": #Rename - params=parameters.replace(",","\",\"").replace("➡","\",\"").replace(" ","") - res="%s.rename(\"%s\")" % (internal,params) + params=parameters.replace(",","\",\"").replace("➡","\":\"").replace(" ","") + res="%s.rename({\"%s\"})" % (internal,params) expr= ("%s%s%s") % (expr[0:start-2],res,expr[end+1:]) else: res="(%s)" % (internal) diff --git a/relation.py b/relation.py index 510090b..4497358 100644 --- a/relation.py +++ b/relation.py @@ -145,19 +145,19 @@ class relation (object): - def rename(self,*params): - '''Operation rename. Takes an even number of parameters: (old,new,old,new....) - Will replace the 1st parameter with the 2nd, the 3rd with 4th, and so on... + def rename(self,params): + '''Operation rename. Takes a dictionatu + Will replace the itmem with its content. + For example if you want to rename a to b, provide {"a":"b"} If an "old" field doesn't exist, None will be returned''' result=[] newt=relation() newt.header=header(list(self.header.attributes)) - for i in range(len(params)): - if i%2==0: - if (newt.header.rename(params[i],params[i+1])) == False: - return None + for i in params: + if (newt.header.rename(i,params[i])) == False: + return None newt.content=list(self.content) return newt