Index: branches/ast/geniusql/dbtypes.py =================================================================== --- branches/ast/geniusql/dbtypes.py (revision 119) +++ branches/ast/geniusql/dbtypes.py (revision 128) @@ -48,14 +48,19 @@ def default_adapter(self, pytype): """Return a default adapter instance for the given pytype, dbtype.""" - ptypes = [pytype, None] - for base in pytype.__bases__: - ptypes.append(base) - - for p in ptypes: - if p in self.default_adapters: - return self.default_adapters[p] - - raise TypeError("%s has no default adapter for %s. Looked for: %s" % - (self, pytype, ", ".join([repr(x) for x in ptypes]))) + # Use try for the common case where the pytype is in the dict. + try: + return self.default_adapters[pytype] + except KeyError: + defaults = self.default_adapters + if None in defaults: + return defaults[None] + for p in pytype.__bases__: + if p in defaults: + return defaults[p] + + raise TypeError("%s has no default adapter for %s. Looked for: " + "%s, None, %s" % + (self, pytype, pytype, + ", ".join([repr(x) for x in ptype.__bases__]))) Index: branches/ast/geniusql/deparse.py =================================================================== --- branches/ast/geniusql/deparse.py (revision 124) +++ branches/ast/geniusql/deparse.py (revision 128) @@ -48,8 +48,5 @@ def __cmp__(self, other): - if isinstance(other, SQLExpression): - return cmp(self.sql, other.sql) - raise TypeError("can't compare %s to %s" % (type(self), type(other)), - other) + return cmp(self.sql, other.sql) def __repr__(self): @@ -152,8 +149,6 @@ """Return an SQLExpression for the given sql of the given pytype.""" self.exprcount += 1 - name = "expr%s" % self.exprcount - dbtype = self.typeset.database_type(pytype) - e = SQLExpression(sql, name, dbtype, pytype) + e = SQLExpression(sql, "expr%s" % self.exprcount, dbtype, pytype) e.adapter = adapter or dbtype.default_adapter(pytype) return e Index: branches/ast/geniusql/select.py =================================================================== --- branches/ast/geniusql/select.py (revision 126) +++ branches/ast/geniusql/select.py (revision 128) @@ -240,10 +240,26 @@ alias = t.alias or t.qname table = t.table - for a in attrs: - self._copy_column(table, alias, a) + for colkey in attrs: + col = table[colkey] + if colkey in self.output_cols: + # Get the key for the table. + colkey = '%s_%s' % (table.schema.key_for(table), colkey) + colname = '%s_%s' % (alias, col.name) + colqname = self.db.quote(colname) + selname = '%s.%s AS %s' % (alias, col.qname, colqname) + else: + colname = col.name + colqname = col.qname + selname = '%s.%s' % (alias, colqname) + self.input_list.append(selname) + self.output.append((colkey, colname, colqname)) + self.output_cols[colkey] = col else: # 'relation' is a single Table object. - for a in query.attributes: - self._copy_column(relation, None, a) + for colkey in query.attributes: + col = relation[colkey] + self.input_list.append(col.qname) + self.output.append((colkey, col.name, col.qname)) + self.output_cols[colkey] = col if query.order is None: @@ -278,33 +294,4 @@ newtable[colkey] = newcol return newtable - - def _copy_column(self, table, alias, colkey): - """Copy the given column from the given table into our result table. - - alias: the name that will be used for the given source table in the - FROM clause of the SQL SELECT statement. If None, this signifies - that the "SELECT columnlist FROM table" only references a single - table, in which case the column list will not use dotted column - names. - """ - col = table[colkey] - - colname = col.name - colqname = col.qname - if alias is None: - # Single table. - selname = colqname - else: - selname = '%s.%s' % (alias, colqname) - - if colkey in self.output_cols: - # Get the key for the table. - colkey = '%s_%s' % (table.schema.key_for(table), colkey) - colname = '%s_%s' % (table.name, colname) - colqname = self.db.quote(colname) - selname = '%s AS %s' % (selname, colqname) - self.input_list.append(selname) - self.output.append((colkey, colname, colqname)) - self.output_cols[colkey] = col def sql(self, distinct=False, limit=None, into=""):