text
stringlengths
0
828
""""""
# pylint: disable-msg=C0111
def wrapper(*args, **kwargs):
with Context.current().transaction():
return wrapped(*args, **kwargs)
return functools.update_wrapper(wrapper, wrapped)"
4702,"def execute(stmt, args=()):
""""""
Execute an SQL statement. Returns the number of affected rows.
""""""
ctx = Context.current()
with ctx.mdr:
cursor = ctx.execute(stmt, args)
row_count = cursor.rowcount
_safe_close(cursor)
return row_count"
4703,"def query(stmt, args=(), factory=None):
""""""
Execute a query. This returns an iterator of the result set.
""""""
ctx = Context.current()
factory = ctx.default_factory if factory is None else factory
with ctx.mdr:
return factory(ctx.execute(stmt, args), ctx.mdr)"
4704,"def query_row(stmt, args=(), factory=None):
""""""
Execute a query. Returns the first row of the result set, or `None`.
""""""
for row in query(stmt, args, factory):
return row
return None"
4705,"def query_value(stmt, args=(), default=None):
""""""
Execute a query, returning the first value in the first row of the
result set. If the query returns no result set, a default value is
returned, which is `None` by default.
""""""
for row in query(stmt, args, TupleFactory):
return row[0]
return default"
4706,"def execute_proc(procname, args=()):
""""""
Execute a stored procedure. Returns the number of affected rows.
""""""
ctx = Context.current()
with ctx.mdr:
cursor = ctx.execute_proc(procname, args)
row_count = cursor.rowcount
_safe_close(cursor)
return row_count"
4707,"def query_proc(procname, args=(), factory=None):
""""""
Execute a stored procedure. This returns an iterator of the result set.
""""""
ctx = Context.current()
factory = ctx.default_factory if factory is None else factory
with ctx.mdr:
return factory(ctx.execute_proc(procname, args), ctx.mdr)"
4708,"def query_proc_row(procname, args=(), factory=None):
""""""
Execute a stored procedure. Returns the first row of the result set,
or `None`.
""""""
for row in query_proc(procname, args, factory):
return row
return None"
4709,"def query_proc_value(procname, args=(), default=None):
""""""
Execute a stored procedure, returning the first value in the first row
of the result set. If it returns no result set, a default value is
returned, which is `None` by default.
""""""
for row in query_proc(procname, args, TupleFactory):
return row[0]
return default"
4710,"def make_placeholders(seq, start=1):
""""""
Generate placeholders for the given sequence.
""""""
if len(seq) == 0:
raise ValueError('Sequence must have at least one element.')
param_style = Context.current().param_style
placeholders = None
if isinstance(seq, dict):
if param_style in ('named', 'pyformat'):
template = ':%s' if param_style == 'named' else '%%(%s)s'
placeholders = (template % key
for key in six.iterkeys(seq))
elif isinstance(seq, (list, tuple)):
if param_style == 'numeric':
placeholders = (':%d' % i
for i in xrange(start, start + len(seq)))
elif param_style in ('qmark', 'format', 'pyformat'):
placeholders = itertools.repeat(
'?' if param_style == 'qmark' else '%s',
len(seq))
if placeholders is None:
raise NotSupported(
""Param style '%s' does not support sequence type '%s'"" % (
param_style, seq.__class__.__name__))