| 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)]) |
|---|
| 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 |
|---|
| 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)) |
|---|
| 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 |
|---|