mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-22 08:56:34 +03:00
Fixed fast execute functions with Python 3
This commit is contained in:
parent
a95fd3df1a
commit
2e2dcd536b
|
@ -1177,7 +1177,7 @@ def execute_batch(cur, sql, argslist, page_size=100):
|
|||
"""
|
||||
for page in _paginate(argslist, page_size=page_size):
|
||||
sqls = [cur.mogrify(sql, args) for args in page]
|
||||
cur.execute(";".join(sqls))
|
||||
cur.execute(b";".join(sqls))
|
||||
|
||||
|
||||
def execute_values(cur, sql, argslist, template=None, page_size=100):
|
||||
|
@ -1219,5 +1219,7 @@ def execute_values(cur, sql, argslist, template=None, page_size=100):
|
|||
for page in _paginate(argslist, page_size=page_size):
|
||||
if template is None:
|
||||
template = '(%s)' % ','.join(['%s'] * len(page[0]))
|
||||
values = ",".join(cur.mogrify(template, args) for args in page)
|
||||
values = b",".join(cur.mogrify(template, args) for args in page)
|
||||
if isinstance(values, bytes) and _sys.version_info[0] > 2:
|
||||
values = values.decode(_ext.encodings[cur.connection.encoding])
|
||||
cur.execute(sql % (values,))
|
||||
|
|
|
@ -1829,7 +1829,7 @@ class TestFastExecute(ConnectingTestCase):
|
|||
page_size=10)
|
||||
|
||||
# last command was 5 statements
|
||||
self.assertEqual(sum(c == ';' for c in cur.query), 4)
|
||||
self.assertEqual(sum(c == u';' for c in cur.query.decode('ascii')), 4)
|
||||
|
||||
cur.execute("select id, val from testfast order by id")
|
||||
self.assertEqual(cur.fetchall(), [(i, i * 10) for i in range(25)])
|
||||
|
@ -1886,7 +1886,7 @@ class TestFastExecute(ConnectingTestCase):
|
|||
page_size=10)
|
||||
|
||||
# last statement was 5 tuples (one parens is for the fields list)
|
||||
self.assertEqual(sum(c == '(' for c in cur.query), 6)
|
||||
self.assertEqual(sum(c == '(' for c in cur.query.decode('ascii')), 6)
|
||||
|
||||
cur.execute("select id, val from testfast order by id")
|
||||
self.assertEqual(cur.fetchall(), [(i, i * 10) for i in range(25)])
|
||||
|
|
Loading…
Reference in New Issue
Block a user