cursor.close()
@contextmanager
- def execute(self, statement, depth=0):
+ def execute(self, statement, depth=0, context=None):
# two frames, accounting for execute() and @contextmanager
frame = inspect.currentframe(depth + 2)
with self.cursor() as cursor:
f_globals = None
-
f_locals = frame.f_locals
- context = dict(**f_locals)
+
+ if context == None:
+ context = dict(**f_locals)
start = 0
while True:
statement = '%s%%(%s)s%s' % (statement[0:percent], key, statement[start + 1:])
start = percent + len(key) + 4
- elif next == '%':
+ elif next in ('%', 's'):
start = percent + 2
else:
assert False
with self.execute(statement, 1) as cursor:
return cursor.callproc(procedure, *parameters)
- def run(self, statement):
- with self.execute(statement, 1) as cursor:
+ def run(self, statement, context=None):
+ with self.execute(statement, 1, context) as cursor:
return cursor.rowcount
@contextmanager