Contact: fumanchu@aminus.org

Log in as guest/geniusql to create tickets

Changeset 128

Show
Ignore:
Timestamp:
08/10/07 19:20:02
Author:
fumanchu
Message:

Various optimizations.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/ast/geniusql/dbtypes.py

    r127 r128  
    4848    def default_adapter(self, pytype): 
    4949        """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__]))) 
    6065 
    6166 
  • branches/ast/geniusql/deparse.py

    r127 r128  
    4848     
    4949    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) 
    5451     
    5552    def __repr__(self): 
     
    152149        """Return an SQLExpression for the given sql of the given pytype.""" 
    153150        self.exprcount += 1 
    154         name = "expr%s" % self.exprcount 
    155          
    156151        dbtype = self.typeset.database_type(pytype) 
    157         e = SQLExpression(sql, name, dbtype, pytype) 
     152        e = SQLExpression(sql, "expr%s" % self.exprcount, dbtype, pytype) 
    158153        e.adapter = adapter or dbtype.default_adapter(pytype) 
    159154        return e 
  • branches/ast/geniusql/select.py

    r127 r128  
    240240                    alias = t.alias or t.qname 
    241241                    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 
    244257            else: 
    245258                # '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 
    248264         
    249265        if query.order is None: 
     
    278294            newtable[colkey] = newcol 
    279295        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 the 
    285             FROM clause of the SQL SELECT statement. If None, this signifies 
    286             that the "SELECT columnlist FROM table" only references a single 
    287             table, in which case the column list will not use dotted column 
    288             names. 
    289         """ 
    290         col = table[colkey] 
    291          
    292         colname = col.name 
    293         colqname = col.qname 
    294         if alias is None: 
    295             # Single table. 
    296             selname = colqname 
    297         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] = col 
    309296     
    310297    def sql(self, distinct=False, limit=None, into=""):