Changeset 81
- Timestamp:
- 05/03/07 13:08:27
- Files:
-
- trunk/geniusql/codewalk.py (modified) (1 diff)
- trunk/geniusql/logic.py (modified) (1 diff)
- trunk/geniusql/objects.py (modified) (2 diffs)
- trunk/geniusql/select.py (modified) (1 diff)
- trunk/geniusql/test/test_firebird.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/geniusql/codewalk.py
r80 r81 755 755 ip += 1 756 756 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. 757 769 terms = self.targets.get(ip) 758 770 if terms: trunk/geniusql/logic.py
r80 r81 440 440 return Expression(func, earlybind=False) 441 441 442 443 def 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 437 437 def _select_lazy(self, restriction=None, **kwargs): 438 438 """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) 447 440 448 441 attrs = self.keys() … … 697 690 pk = "" 698 691 692 # Just to be sure... 693 try: 694 self.db.execute_ddl('DROP TABLE %s;' % table.qname) 695 except: 696 pass 699 697 self.db.execute_ddl('CREATE TABLE %s (%s%s);' % 700 698 (table.qname, ", ".join(fields), pk)) trunk/geniusql/select.py
r80 r81 109 109 The order of sequences must match the order of tables given in the 110 110 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. 111 115 restriction: an Expression (or lambda) to restrict the rows returned; 112 116 if given, this will be used to construct a WHERE clause. The args trunk/geniusql/test/test_firebird.py
r80 r81 32 32 # Isolate schema changes from one test to the next. 33 33 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 35 43 36 44 if __name__ == "__main__":
