mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2026-03-13 08:00:02 +08:00
fixup
This commit is contained in:
@@ -65,7 +65,6 @@ def numeric_part(s):
|
||||
|
||||
|
||||
class Connection(_mysql.connection):
|
||||
|
||||
"""MySQL Database Connection Object"""
|
||||
|
||||
default_cursor = cursors.Cursor
|
||||
|
||||
@@ -110,18 +110,18 @@ class BaseCursor(object):
|
||||
if isinstance(args, (tuple, list)):
|
||||
if PY2:
|
||||
args = tuple(map(ensure_bytes, args))
|
||||
return tuple(conn.escape(arg) for arg in args)
|
||||
return tuple(conn.literal(arg) for arg in args)
|
||||
elif isinstance(args, dict):
|
||||
if PY2:
|
||||
args = dict((ensure_bytes(key), ensure_bytes(val)) for
|
||||
(key, val) in args.items())
|
||||
return dict((key, conn.escape(val)) for (key, val) in args.items())
|
||||
return dict((key, conn.literal(val)) for (key, val) in args.items())
|
||||
else:
|
||||
# If it's not a dictionary let's try escaping it anyways.
|
||||
# Worst case it will throw a Value error
|
||||
if PY2:
|
||||
args = ensure_bytes(args)
|
||||
return conn.escape(args)
|
||||
return conn.literal(args)
|
||||
|
||||
def _check_executed(self):
|
||||
if not self._executed:
|
||||
|
||||
@@ -53,12 +53,12 @@ def test_executemany():
|
||||
# list args
|
||||
data = range(10)
|
||||
cursor.executemany("insert into test (data) values (%s)", data)
|
||||
assert cursor._executed.endswith(",(7),(8),(9)"), 'execute many with %s not in one query'
|
||||
assert cursor._executed.endswith(b",(7),(8),(9)"), 'execute many with %s not in one query'
|
||||
|
||||
# dict args
|
||||
data_dict = [{'data': i} for i in range(10)]
|
||||
cursor.executemany("insert into test (data) values (%(data)s)", data_dict)
|
||||
assert cursor._executed.endswith(",(7),(8),(9)"), 'execute many with %(data)s not in one query'
|
||||
assert cursor._executed.endswith(b",(7),(8),(9)"), 'execute many with %(data)s not in one query'
|
||||
|
||||
# %% in column set
|
||||
cursor.execute("""\
|
||||
@@ -69,6 +69,6 @@ def test_executemany():
|
||||
q = "INSERT INTO percent_test (`A%%`, `B%%`) VALUES (%s, %s)"
|
||||
assert MySQLdb.cursors.RE_INSERT_VALUES.match(q) is not None
|
||||
cursor.executemany(q, [(3, 4), (5, 6)])
|
||||
assert cursor._executed.endswith("(3, 4),(5, 6)"), "executemany with %% not in one query"
|
||||
assert cursor._executed.endswith(b"(3, 4),(5, 6)"), "executemany with %% not in one query"
|
||||
finally:
|
||||
cursor.execute("DROP TABLE IF EXISTS percent_test")
|
||||
|
||||
Reference in New Issue
Block a user