Changeset 128
- Timestamp:
- 08/10/07 19:20:02
- Files:
-
- branches/ast/geniusql/dbtypes.py (modified) (1 diff)
- branches/ast/geniusql/deparse.py (modified) (2 diffs)
- branches/ast/geniusql/select.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/ast/geniusql/dbtypes.py
r127 r128 48 48 def default_adapter(self, pytype): 49 49 """Return a default adapter instance for the given pytype, dbtype.""" 50 ptypes = [pytype, None] 51 for base in pytype.__bases__: 52 ptypes.append(base) 53 54 for p in ptypes: 55 if p in self.default_adapters: 56 return self.default_adapters[p] 57 58 raise TypeError("%s has no default adapter for %s. Looked for: %s" % 59 (self, pytype, ", ".join([repr(x) for x in ptypes]))) 50 # Use try for the common case where the pytype is in the dict. 51 try: 52 return self.default_adapters[pytype] 53 except KeyError: 54 defaults = self.default_adapters 55 if None in defaults: 56 return defaults[None] 57 for p in pytype.__bases__: 58 if p in defaults: 59 return defaults[p] 60 61 raise TypeError("%s has no default adapter for %s. Looked for: " 62 "%s, None, %s" % 63 (self, pytype, pytype, 64 ", ".join([repr(x) for x in ptype.__bases__]))) 60 65 61 66 branches/ast/geniusql/deparse.py
r127 r128 48 48 49 49 def __cmp__(self, other): 50 if isinstance(other, SQLExpression): 51 return cmp(self.sql, other.sql) 52 raise TypeError("can't compare %s to %s" % (type(self), type(other)), 53 other) 50 return cmp(self.sql, other.sql) 54 51 55 52 def __repr__(self): … … 152 149 """Return an SQLExpression for the given sql of the given pytype.""" 153 150 self.exprcount += 1 154 name = "expr%s" % self.exprcount155 156 151 dbtype = self.typeset.database_type(pytype) 157 e = SQLExpression(sql, name, dbtype, pytype)152 e = SQLExpression(sql, "expr%s" % self.exprcount, dbtype, pytype) 158 153 e.adapter = adapter or dbtype.default_adapter(pytype) 159 154 return e branches/ast/geniusql/select.py
r127 r128 240 240 alias = t.alias or t.qname 241 241 table = t.table 242 for a in attrs: 243 self._copy_column(table, alias, a) 242 for colkey in attrs: 243 col = table[colkey] 244 if colkey in self.output_cols: 245 # Get the key for the table. 246 colkey = '%s_%s' % (table.schema.key_for(table), colkey) 247 colname = '%s_%s' % (alias, col.name) 248 colqname = self.db.quote(colname) 249 selname = '%s.%s AS %s' % (alias, col.qname, colqname) 250 else: 251 colname = col.name 252 colqname = col.qname 253 selname = '%s.%s' % (alias, colqname) 254 self.input_list.append(selname) 255 self.output.append((colkey, colname, colqname)) 256 self.output_cols[colkey] = col 244 257 else: 245 258 # 'relation' is a single Table object. 246 for a in query.attributes: 247 self._copy_column(relation, None, a) 259 for colkey in query.attributes: 260 col = relation[colkey] 261 self.input_list.append(col.qname) 262 self.output.append((colkey, col.name, col.qname)) 263 self.output_cols[colkey] = col 248 264 249 265 if query.order is None: … … 278 294 newtable[colkey] = newcol 279 295 return newtable 280 281 def _copy_column(self, table, alias, colkey):282 """Copy the given column from the given table into our result table.283 284 alias: the name that will be used for the given source table in the285 FROM clause of the SQL SELECT statement. If None, this signifies286 that the "SELECT columnlist FROM table" only references a single287 table, in which case the column list will not use dotted column288 names.289 """290 col = table[colkey]291 292 colname = col.name293 colqname = col.qname294 if alias is None:295 # Single table.296 selname = colqname297 else:298 selname = '%s.%s' % (alias, colqname)299 300 if colkey in self.output_cols:301 # Get the key for the table.302 colkey = '%s_%s' % (table.schema.key_for(table), colkey)303 colname = '%s_%s' % (table.name, colname)304 colqname = self.db.quote(colname)305 selname = '%s AS %s' % (selname, colqname)306 self.input_list.append(selname)307 self.output.append((colkey, colname, colqname))308 self.output_cols[colkey] = col309 296 310 297 def sql(self, distinct=False, limit=None, into=""):
