Logo Search packages:      
Sourcecode: relational version File versions  Download package

def relational::relation::relation::update (   self,
  expr,
  dic 
)

Update, expr must be a valid boolean expression, can contain field names,
constant, math operations and boolean ones.
This operation will change the relation itself instead of generating a new one,
updating all the tuples that make expr true.
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.

Definition at line 424 of file relation.py.

00424                              :
        '''Update, expr must be a valid boolean expression, can contain field names,
        constant, math operations and boolean ones.
        This operation will change the relation itself instead of generating a new one,
        updating all the tuples that make expr true.
        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.'''
        affected=0
        attributes={}
        keys=dic.keys() #List of headers to modify
        f_ids=self.header.getAttributesId(keys) #List of indexes corresponding to keys
        
        #new_content=[] #New content of the relation
        for i in self.content:
            for j in range(len(self.header.attributes)):
                #Giving to the field it's right format (hopefully)
                if i[j].isdigit():
                    attributes[self.header.attributes[j]]=int(i[j])
                elif rstring(i[j]).isFloat():
                    attributes[self.header.attributes[j]]=float(i[j])
                elif isDate(i[j]):
                    attributes[self.header.attributes[j]]=rdate(i[j])
                else:
                    attributes[self.header.attributes[j]]=i[j]
            if eval(expr,attributes): #If expr is true, changing the tuple
                affected+=1
                new_tuple=list(i)
                #Deleting the tuple, instead of changing it, so other
                #relations can still point to the same list without
                #being affected.
                self.content.remove(i) 
                for k in range(len(keys)):
                    new_tuple[f_ids[k]]=str(dic[keys[k]])
                self.content.append(new_tuple)
        return affected
    def insert(self,values):


Generated by  Doxygen 1.6.0   Back to index