Contact: fumanchu@aminus.org

Log in as guest/geniusql to create tickets

Changeset 81

Show
Ignore:
Timestamp:
05/03/07 13:08:27
Author:
fumanchu
Message:

New logic.combine(expr, kwargs) function (and sundry).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/geniusql/codewalk.py

    r80 r81  
    755755                ip += 1 
    756756         
     757        # This is where we do folding of logical AND and OR operators. 
     758        # The Python code just writes "a AND b", but the VM (bytecode) 
     759        # acts more like assembly, using conditional JUMP instructions to 
     760        # implement logical operators. The map stored in self.targets is 
     761        # of the form: 
     762        #     {JUMP target: [(self.stack[-1], 'and'), ...]} 
     763        # where "JUMP target" is the instruction number of the bytecode 
     764        # which is the target of the JUMP, and each item in the value list 
     765        # is a tuple of (top of the calling stack, operation). 
     766        # It's a list because a single bytecode may be the target of 
     767        # multiple JUMP instructions. 
     768        # See visit_JUMP_IF_FALSE / TRUE. 
    757769        terms = self.targets.get(ip) 
    758770        if terms: 
  • trunk/geniusql/logic.py

    r80 r81  
    440440    return Expression(func, earlybind=False) 
    441441 
     442 
     443def combine(expr, kwargs): 
     444    """Return a single Expression (or None) for the given expr and kwargs. 
     445     
     446    The supplied expr may be a lambda, an Expression, or None. 
     447    The kwargs may be an empty dict. 
     448    """ 
     449    if expr is not None and not isinstance(expr, Expression): 
     450        expr = Expression(expr) 
     451    if kwargs: 
     452        f = filter(**kwargs) 
     453        if expr is None: 
     454            expr = f 
     455        else: 
     456            expr += f 
     457    return expr 
     458 
     459 
  • trunk/geniusql/objects.py

    r80 r81  
    437437    def _select_lazy(self, restriction=None, **kwargs): 
    438438        """Yield data dicts matching the given restriction.""" 
    439         if restriction and not isinstance(restriction, logic.Expression): 
    440             restriction = logic.Expression(restriction) 
    441         if kwargs: 
    442             f = logic.filter(**kwargs) 
    443             if restriction: 
    444                 restriction += f 
    445             else: 
    446                 restriction = f 
     439        restriction = logic.combine(restriction, kwargs) 
    447440         
    448441        attrs = self.keys() 
     
    697690            pk = "" 
    698691         
     692        # Just to be sure... 
     693        try: 
     694            self.db.execute_ddl('DROP TABLE %s;' % table.qname) 
     695        except: 
     696            pass 
    699697        self.db.execute_ddl('CREATE TABLE %s (%s%s);' % 
    700698                            (table.qname, ", ".join(fields), pk)) 
  • trunk/geniusql/select.py

    r80 r81  
    109109        The order of sequences must match the order of tables given in the 
    110110        relation (and therefore the restriction args, if applicable). 
     111        A final option is to pass a lambda (or Expression) which returns 
     112        the attributes as a tuple or list; e.g.: 
     113            lambda t1, t2: (t1.a, t1.b - now(), t1.c + t2.a) 
     114        This allows access to binary operations and builtin functions. 
    111115    restriction: an Expression (or lambda) to restrict the rows returned; 
    112116        if given, this will be used to construct a WHERE clause. The args 
  • trunk/geniusql/test/test_firebird.py

    r80 r81  
    3232        # Isolate schema changes from one test to the next. 
    3333        reload(zoo_fixture) 
    34         zoo_fixture.run(DB_class, opts['name'], opts) 
     34        try: 
     35            zoo_fixture.run(DB_class, opts['name'], opts) 
     36        except kinterbasdb.OperationalError, e: 
     37            if e.args[0] == -902 and 'Failed to establish a connection' in e.args[1]: 
     38                import warnings 
     39                warnings.warn("Could not connect to Firebird server. " 
     40                              "The Firebird test will not be run.") 
     41            else: 
     42                raise 
    3543 
    3644if __name__ == "__main__":