Contact: fumanchu@aminus.org

Log in as guest/dejavu to create tickets

Changeset 168

Show
Ignore:
Timestamp:
02/14/06 15:52:28
Author:
fumanchu
Message:

Fixed some errors when fetch returns empty col_defs.

Files:

Legend:

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

    r167 r168  
    968968        sql, imperfect = self.select(cls, expr) 
    969969        data, col_defs = self.fetch(sql) 
    970          
    971         columns = dict([(col[0], (index, col[1])) for index, col 
    972                         in enumerate(col_defs)]) 
    973          
    974         # Get specs on properties. Put the identifier properties 
    975         # first, in case other fields depend upon them. 
    976         # See load_expanded, for example. 
    977         props = [] 
    978         idnames = [prop.key for prop in cls.identifiers] 
    979         for key in idnames + [x for x in cls.properties() if x not in idnames]: 
    980             index, ftype = columns[self.column_name(clsname, key, quoted=False)] 
    981             subtype = self.expanded_columns.get((clsname, key)) 
    982             props.append((key, index, ftype, subtype)) 
    983          
    984         consume = self.fromAdapter.consume 
    985         for row in data: 
    986             unit = cls() 
    987             for key, index, ftype, subtype in props: 
    988                 value = row[index] 
    989                 if subtype: 
    990                     self.load_expanded(unit, key, subtype) 
    991                 else: 
    992                     consume(unit, key, value, ftype) 
     970        if data: 
     971            columns = dict([(col[0], (index, col[1])) for index, col 
     972                            in enumerate(col_defs)]) 
    993973             
    994             # If our SQL is imperfect, don't yield it to the 
    995             # caller unless it passes expr(unit). 
    996             if (not imperfect) or expr(unit): 
    997                 unit.cleanse() 
    998                 yield unit 
     974            # Get specs on properties. Put the identifier properties 
     975            # first, in case other fields depend upon them. 
     976            # See load_expanded, for example. 
     977            props = [] 
     978            idnames = [prop.key for prop in cls.identifiers] 
     979            for key in idnames + [x for x in cls.properties() if x not in idnames]: 
     980                index, ftype = columns[self.column_name(clsname, key, quoted=False)] 
     981                subtype = self.expanded_columns.get((clsname, key)) 
     982                props.append((key, index, ftype, subtype)) 
     983             
     984            consume = self.fromAdapter.consume 
     985            for row in data: 
     986                unit = cls() 
     987                for key, index, ftype, subtype in props: 
     988                    value = row[index] 
     989                    if subtype: 
     990                        self.load_expanded(unit, key, subtype) 
     991                    else: 
     992                        consume(unit, key, value, ftype) 
     993                 
     994                # If our SQL is imperfect, don't yield it to the 
     995                # caller unless it passes expr(unit). 
     996                if (not imperfect) or expr(unit): 
     997                    unit.cleanse() 
     998                    yield unit 
    999999     
    10001000    def reserve(self, unit): 
     
    12911291        sql, imp, supplied_cols = self.multiselect(classes, expr) 
    12921292        data, recvd_cols = self.fetch(sql) 
    1293          
    1294         # Get specs on properties. 
    1295         props = [] 
    1296         for sup, rec in zip(supplied_cols, recvd_cols): 
    1297             c, key = sup 
    1298             name, ftype = rec[0], rec[1] 
    1299             subtype = self.expanded_columns.get((c.__name__, key)) 
    1300             props.append((c, key, ftype, subtype)) 
    1301          
    1302         consume = self.fromAdapter.consume 
    1303         for row in data: 
    1304             index = 0 
    1305             units = {} 
    1306             for c, key, ftype, subtype in props: 
    1307                 if c in units: 
    1308                     unit = units[c] 
    1309                 else: 
    1310                     units[c] = unit = c() 
    1311                 value = row[index] 
    1312                 if subtype: 
    1313                     self.load_expanded(unit, key, subtype) 
    1314                 else: 
    1315                     consume(unit, key, value, ftype) 
    1316                 index += 1 
     1293        if data: 
     1294            # Get specs on properties. 
     1295            props = [] 
     1296            for sup, rec in zip(supplied_cols, recvd_cols): 
     1297                c, key = sup 
     1298                name, ftype = rec[0], rec[1] 
     1299                subtype = self.expanded_columns.get((c.__name__, key)) 
     1300                props.append((c, key, ftype, subtype)) 
    13171301             
    1318             unitset = [] 
    1319             for cls in classes: 
    1320                 unit = units[cls] 
    1321                 unit.cleanse() 
    1322                 unitset.append(unit) 
    1323              
    1324             # If our SQL is imperfect, don't yield units to the 
    1325             # caller unless they pass expr(unit). 
    1326             acceptable = True 
    1327             if imp: 
    1328                 acceptable = expr(*unitset) 
    1329             if acceptable: 
    1330                 yield unitset 
     1302            consume = self.fromAdapter.consume 
     1303            for row in data: 
     1304                index = 0 
     1305                units = {} 
     1306                for c, key, ftype, subtype in props: 
     1307                    if c in units: 
     1308                        unit = units[c] 
     1309                    else: 
     1310                        units[c] = unit = c() 
     1311                    value = row[index] 
     1312                    if subtype: 
     1313                        self.load_expanded(unit, key, subtype) 
     1314                    else: 
     1315                        consume(unit, key, value, ftype) 
     1316                    index += 1 
     1317                 
     1318                unitset = [] 
     1319                for cls in classes: 
     1320                    unit = units[cls] 
     1321                    unit.cleanse() 
     1322                    unitset.append(unit) 
     1323                 
     1324                # If our SQL is imperfect, don't yield units to the 
     1325                # caller unless they pass expr(unit). 
     1326                acceptable = True 
     1327                if imp: 
     1328                    acceptable = expr(*unitset) 
     1329                if acceptable: 
     1330                    yield unitset 
    13311331     
    13321332    #                               Schemas                               # 
  • trunk/storage/storeado.py

    r167 r168  
    398398     
    399399    def has_storage(self, cls): 
    400         names = [x[2] for x in self.get_tables()[0]] 
     400        data, col_defs = self.get_tables() 
     401        names = [x[2] for x in data] 
    401402        return self.table_name(cls.__name__, quoted=False) in names 
    402403