From dfb3f19acfdb6868b4502972ee9f17529fc3415d Mon Sep 17 00:00:00 2001 From: LtWorf Date: Fri, 1 Apr 2011 06:38:47 +0000 Subject: [PATCH] - Raises exception for wrong relational operations git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@295 014f5005-505e-4b48-8d0a-63407b615a7c --- CHANGELOG | 1 + relational/relation.py | 20 ++++++++------------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 93899af..a6c1e34 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,5 @@ 1.1 +- Incorrect relational operations now raise an exception instead of returning None 1.0 - Adds history in the GUI diff --git a/relational/relation.py b/relational/relation.py index 827d628..4ebb77e 100644 --- a/relational/relation.py +++ b/relational/relation.py @@ -133,7 +133,7 @@ class relation (object): It is possible to use rename on attributes and then use the product''' if (self.__class__!=other.__class__)or(self.header.sharedAttributes(other.header)!=0): - return None + raise Exception('Unable to perform product on relations with colliding attributes') newt=relation() newt.header=header(self.header.attributes+other.header.attributes) @@ -159,14 +159,10 @@ class relation (object): attributes1.append(i) attributes=attributes1 - #If source and dest has the same number of attributes, we are just rearranging - #so we won't need to check for duplicated entries - attributes_same_count=len(attributes)==len(self.header.attributes) - ids=self.header.getAttributesId(attributes) - if len(ids)==0: - return None + if len(ids)==0 or len(ids)!=len(attributes): + raise Exception('Invalid attributes for projection') newt=relation() #Create the header h=[] @@ -186,7 +182,7 @@ class relation (object): '''Operation rename. Takes a dictionary 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() @@ -194,7 +190,7 @@ class relation (object): for old,new in params.iteritems(): if (newt.header.rename(old,new)) == False: - return None + raise Exception('Unable to find attribute: %s' % old) newt.content=self.content newt._readonly=True @@ -208,7 +204,7 @@ class relation (object): It is possible to use projection and rename to make headers match.''' other=self._rearrange_(other) #Rearranges attributes' order if (self.__class__!=other.__class__)or(self.header!=other.header): - return None + raise Exception('Unable to perform intersection on relations with different attributes') newt=relation() newt.header=header(list(self.header.attributes)) @@ -223,7 +219,7 @@ class relation (object): It is possible to use projection and rename to make headers match.''' other=self._rearrange_(other) #Rearranges attributes' order if (self.__class__!=other.__class__)or(self.header!=other.header): - return None + raise Exception('Unable to perform difference on relations with different attributes') newt=relation() newt.header=header(list(self.header.attributes)) @@ -267,7 +263,7 @@ class relation (object): It is possible to use projection and rename to make headers match.''' other=self._rearrange_(other) #Rearranges attributes' order if (self.__class__!=other.__class__)or(self.header!=other.header): - return None + raise Exception('Unable to perform union on relations with different attributes') newt=relation() newt.header=header(list(self.header.attributes))