text stringlengths 0 828 |
|---|
return ', '.join(placeholders)" |
4711,"def make_file_object_logger(fh): |
"""""" |
Make a logger that logs to the given file object. |
"""""" |
def logger_func(stmt, args, fh=fh): |
"""""" |
A logger that logs everything sent to a file object. |
"""""" |
now = datetime.datetime.now() |
six.print_(""Executing (%s):"" % now.isoformat(), file=fh) |
six.print_(textwrap.dedent(stmt), file=fh) |
six.print_(""Arguments:"", file=fh) |
pprint.pprint(args, fh) |
return logger_func" |
4712,"def current(cls, with_exception=True): |
"""""" |
Returns the current database context. |
"""""" |
if with_exception and len(cls.stack) == 0: |
raise NoContext() |
return cls.stack.top()" |
4713,"def transaction(self): |
"""""" |
Sets up a context where all the statements within it are ran within |
a single database transaction. For internal use only. |
"""""" |
# The idea here is to fake the nesting of transactions. Only when |
# we've gotten back to the topmost transaction context do we actually |
# commit or rollback. |
with self.mdr: |
try: |
self._depth += 1 |
yield self |
self._depth -= 1 |
except self.mdr.OperationalError: |
# We've lost the connection, so there's no sense in |
# attempting to roll back back the transaction. |
self._depth -= 1 |
raise |
except: |
self._depth -= 1 |
if self._depth == 0: |
self.mdr.rollback() |
raise |
if self._depth == 0: |
self.mdr.commit()" |
4714,"def cursor(self): |
"""""" |
Get a cursor for the current connection. For internal use only. |
"""""" |
cursor = self.mdr.cursor() |
with self.transaction(): |
try: |
yield cursor |
if cursor.rowcount != -1: |
self.last_row_count = cursor.rowcount |
self.last_row_id = getattr(cursor, 'lastrowid', None) |
except: |
self.last_row_count = None |
self.last_row_id = None |
_safe_close(cursor) |
raise" |
4715,"def execute(self, stmt, args): |
"""""" |
Execute a statement, returning a cursor. For internal use only. |
"""""" |
self.logger(stmt, args) |
with self.cursor() as cursor: |
cursor.execute(stmt, args) |
return cursor" |
4716,"def execute_proc(self, procname, args): |
"""""" |
Execute a stored procedure, returning a cursor. For internal use |
only. |
"""""" |
self.logger(procname, args) |
with self.cursor() as cursor: |
cursor.callproc(procname, args) |
return cursor" |
4717,"def close(self): |
"""""" |
Close the connection this context wraps. |
"""""" |
self.logger = None |
for exc in _EXCEPTIONS: |
setattr(self, exc, None) |
try: |
self.mdr.close() |
finally: |
self.mdr = None" |
4718,"def connect(self): |
"""""" |
Returns a context that uses this pool as a connection source. |
"""""" |
ctx = Context(self.module, self.create_mediator()) |
ctx.logger = self.logger |
ctx.default_factory = self.default_factory |
return ctx" |
4719,"def close(self): |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.