mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-22 17:06:33 +03:00
Further minimal performance tweaks to execute_values
This commit is contained in:
parent
dc1b4fff90
commit
95226baa9b
|
@ -1241,19 +1241,20 @@ def execute_values(cur, sql, argslist, template=None, page_size=100):
|
||||||
|
|
||||||
for page in _paginate(argslist, page_size=page_size):
|
for page in _paginate(argslist, page_size=page_size):
|
||||||
if template is None:
|
if template is None:
|
||||||
template = '(%s)' % ','.join(['%s'] * len(page[0]))
|
template = b'(' + b','.join([b'%s'] * len(page[0])) + b')'
|
||||||
parts = [pre]
|
parts = pre[:]
|
||||||
for args in page:
|
for args in page:
|
||||||
parts.append(cur.mogrify(template, args))
|
parts.append(cur.mogrify(template, args))
|
||||||
parts.append(b',')
|
parts.append(b',')
|
||||||
parts[-1] = post
|
parts[-1:] = post
|
||||||
cur.execute(b''.join(parts))
|
cur.execute(b''.join(parts))
|
||||||
|
|
||||||
|
|
||||||
def _split_sql(sql):
|
def _split_sql(sql):
|
||||||
"""Split *sql* on a single ``%s`` placeholder.
|
"""Split *sql* on a single ``%s`` placeholder.
|
||||||
|
|
||||||
Return a (pre, post) pair around the ``%s``, with ``%%`` -> ``%`` replacement.
|
Split on the %s, perform %% replacement and return pre, post lists of
|
||||||
|
snippets.
|
||||||
"""
|
"""
|
||||||
curr = pre = []
|
curr = pre = []
|
||||||
post = []
|
post = []
|
||||||
|
@ -1278,4 +1279,4 @@ def _split_sql(sql):
|
||||||
if curr is pre:
|
if curr is pre:
|
||||||
raise ValueError("the query doesn't contain any '%s' placeholder")
|
raise ValueError("the query doesn't contain any '%s' placeholder")
|
||||||
|
|
||||||
return b''.join(pre), b''.join(post)
|
return pre, post
|
||||||
|
|
Loading…
Reference in New Issue
Block a user