Changeset 330

Show
Ignore:
Timestamp:
06/13/04 05:44:35 (5 years ago)
Author:
ed
Message:

Re-wrote the setNonUpdateFields() method to be backend-agnostic. Also
reduced the number of separate queries that were being run: previously, a
query was run for each field in the cursor; now just one query is run, and
the results are determined from that. Got to polish my list comprehension
skills in the process <g>.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/db/dCursorMixin.py

    r329 r330  
    269269         
    270270    def __setNonUpdateFields(self): 
    271         # Set the __nonUpdateFields prop 
    272         self.__nonUpdateFields = [] 
     271        # First, save off the current state. 
    273272        self.__saveProps() 
    274273 
    275         dscrp = self.description 
    276         for fldDesc in dscrp: 
    277             fld = fldDesc[0] 
    278             try: 
    279                 ## TODO: MySQL-specific code ## 
    280                 sql = """select %s from %s limit 1""" % (fld, self.table) 
    281                 self.execute( sql ) 
    282                 # Get the description for this single field 
    283                 dsc = self.description[0] 
    284                 # All members except for the second (display value) should  
    285                 # match. If not, add 'em to the nonUpdateFields list 
    286                 if not ( (fldDesc[1] == dsc[1])  
    287                         and (fldDesc[3] == dsc[3]) and (fldDesc[4] == dsc[4])  
    288                         and (fldDesc[5] == dsc[5]) and (fldDesc[6] == dsc[6]) ): 
    289                     self.__nonUpdateFields.append(fld) 
    290             except: 
    291                 self.__nonUpdateFields.append(fld) 
     274        # This is the current description of the cursor. 
     275        descFlds = self.description 
     276        # Get the raw version of the table 
     277        sql = """select * from %s where 1=0 """ % self.table 
     278        self.execute( sql ) 
     279        # This is the clean version of the table. 
     280        stdFlds = self.description 
     281 
     282        # Restore the original state of the cursor; we have everything 
     283        # we need to determine the non-update fields. 
    292284        self.__restoreProps() 
     285 
     286        # Get all the fields that are not in the table. 
     287        self.__nonUpdateFields = [d[0] for d in descFlds  
     288                if d[0] not in [s[0] for s in stdFlds] ] 
     289        # Extract the remaining fields (no need to test any already excluded 
     290        remFlds = [ d for d in descFlds if d[0] not in self.__nonUpdateFields ] 
     291         
     292        # Now add any for which the members (except the display value,  
     293        # which is in position 2) do not match 
     294        self.__nonUpdateFields += [ b[0] for b in remFlds  
     295                for s in [z for z in stdFlds if z[0] == b[0] ] 
     296                if (b[1] != s[1]) or (b[3] != s[3]) or (b[4] != s[4])  
     297                or (b[5] != s[5]) or (b[6] != s[6]) ] 
    293298     
    294299