()
| 28 | |
| 29 | |
| 30 | def test_executemany(): |
| 31 | conn = connect() |
| 32 | cursor = conn.cursor() |
| 33 | |
| 34 | cursor.execute("create table test (data varchar(10))") |
| 35 | _tables.append("test") |
| 36 | |
| 37 | m = MySQLdb.cursors.RE_INSERT_VALUES.match( |
| 38 | "INSERT INTO TEST (ID, NAME) VALUES (%s, %s)" |
| 39 | ) |
| 40 | assert m is not None, "error parse %s" |
| 41 | assert m.group(3) == "", "group 3 not blank, bug in RE_INSERT_VALUES?" |
| 42 | |
| 43 | m = MySQLdb.cursors.RE_INSERT_VALUES.match( |
| 44 | "INSERT INTO TEST (ID, NAME) VALUES (%(id)s, %(name)s)" |
| 45 | ) |
| 46 | assert m is not None, "error parse %(name)s" |
| 47 | assert m.group(3) == "", "group 3 not blank, bug in RE_INSERT_VALUES?" |
| 48 | |
| 49 | m = MySQLdb.cursors.RE_INSERT_VALUES.match( |
| 50 | "INSERT INTO TEST (ID, NAME) VALUES (%(id_name)s, %(name)s)" |
| 51 | ) |
| 52 | assert m is not None, "error parse %(id_name)s" |
| 53 | assert m.group(3) == "", "group 3 not blank, bug in RE_INSERT_VALUES?" |
| 54 | |
| 55 | m = MySQLdb.cursors.RE_INSERT_VALUES.match( |
| 56 | "INSERT INTO TEST (ID, NAME) VALUES (%(id_name)s, %(name)s) ON duplicate update" |
| 57 | ) |
| 58 | assert m is not None, "error parse %(id_name)s" |
| 59 | assert ( |
| 60 | m.group(3) == " ON duplicate update" |
| 61 | ), "group 3 not ON duplicate update, bug in RE_INSERT_VALUES?" |
| 62 | |
| 63 | # https://github.com/PyMySQL/mysqlclient-python/issues/178 |
| 64 | m = MySQLdb.cursors.RE_INSERT_VALUES.match( |
| 65 | "INSERT INTO bloup(foo, bar)VALUES(%s, %s)" |
| 66 | ) |
| 67 | assert m is not None |
| 68 | |
| 69 | # cursor._executed myst bee |
| 70 | # """ |
| 71 | # insert into test (data) |
| 72 | # values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9) |
| 73 | # """ |
| 74 | # list args |
| 75 | data = [(i,) for i in range(10)] |
| 76 | cursor.executemany("insert into test (data) values (%s)", data) |
| 77 | assert cursor._executed.endswith( |
| 78 | b",(7),(8),(9)" |
| 79 | ), "execute many with %s not in one query" |
| 80 | |
| 81 | # dict args |
| 82 | data_dict = [{"data": i} for i in range(10)] |
| 83 | cursor.executemany("insert into test (data) values (%(data)s)", data_dict) |
| 84 | assert cursor._executed.endswith( |
| 85 | b",(7),(8),(9)" |
| 86 | ), "execute many with %(data)s not in one query" |
| 87 |
nothing calls this directly
no test coverage detected
searching dependent graphs…