diff --git a/lib/extras.py b/lib/extras.py index 85963c9f..2636655a 100644 --- a/lib/extras.py +++ b/lib/extras.py @@ -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,)) diff --git a/tests/test_types_extras.py b/tests/test_types_extras.py index ab8e1707..952208c5 100755 --- a/tests/test_types_extras.py +++ b/tests/test_types_extras.py @@ -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)])