X-Git-Url: https://git.saurik.com/cyql.git/blobdiff_plain/e12c964c25ae9ecbc035c8223057ac00304440d1..51ce7a2715cf156bbb26d9a67d75b6819d0b3425:/__init__.py diff --git a/__init__.py b/__init__.py index 48bc92c..a21ba31 100644 --- a/__init__.py +++ b/__init__.py @@ -52,15 +52,16 @@ class connect(object): 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: @@ -84,7 +85,7 @@ class connect(object): 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 @@ -126,8 +127,8 @@ class connect(object): 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