(self)
| 92 | self.assertIsNone(c2.fetchone()) |
| 93 | |
| 94 | def test_executemany(self): |
| 95 | conn = self.test_connection |
| 96 | cursor = conn.cursor(pymysql.cursors.Cursor) |
| 97 | |
| 98 | m = pymysql.cursors.RE_INSERT_VALUES.match( |
| 99 | "INSERT INTO TEST (ID, NAME) VALUES (%s, %s)" |
| 100 | ) |
| 101 | self.assertIsNotNone(m, "error parse %s") |
| 102 | self.assertEqual(m.group(3), "", "group 3 not blank, bug in RE_INSERT_VALUES?") |
| 103 | |
| 104 | m = pymysql.cursors.RE_INSERT_VALUES.match( |
| 105 | "INSERT INTO TEST (ID, NAME) VALUES (%(id)s, %(name)s)" |
| 106 | ) |
| 107 | self.assertIsNotNone(m, "error parse %(name)s") |
| 108 | self.assertEqual(m.group(3), "", "group 3 not blank, bug in RE_INSERT_VALUES?") |
| 109 | |
| 110 | m = pymysql.cursors.RE_INSERT_VALUES.match( |
| 111 | "INSERT INTO TEST (ID, NAME) VALUES (%(id_name)s, %(name)s)" |
| 112 | ) |
| 113 | self.assertIsNotNone(m, "error parse %(id_name)s") |
| 114 | self.assertEqual(m.group(3), "", "group 3 not blank, bug in RE_INSERT_VALUES?") |
| 115 | |
| 116 | m = pymysql.cursors.RE_INSERT_VALUES.match( |
| 117 | "INSERT INTO TEST (ID, NAME) VALUES (%(id_name)s, %(name)s) ON duplicate update" |
| 118 | ) |
| 119 | self.assertIsNotNone(m, "error parse %(id_name)s") |
| 120 | self.assertEqual( |
| 121 | m.group(3), |
| 122 | " ON duplicate update", |
| 123 | "group 3 not ON duplicate update, bug in RE_INSERT_VALUES?", |
| 124 | ) |
| 125 | |
| 126 | # https://github.com/PyMySQL/PyMySQL/pull/597 |
| 127 | m = pymysql.cursors.RE_INSERT_VALUES.match( |
| 128 | "INSERT INTO bloup(foo, bar)VALUES(%s, %s)" |
| 129 | ) |
| 130 | assert m is not None |
| 131 | |
| 132 | # cursor._executed must bee "insert into test (data) |
| 133 | # values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9)" |
| 134 | # list args |
| 135 | data = range(10) |
| 136 | cursor.executemany("insert into test (data) values (%s)", data) |
| 137 | self.assertTrue( |
| 138 | cursor._executed.endswith(b",(7),(8),(9)"), |
| 139 | "execute many with %s not in one query", |
| 140 | ) |
| 141 | |
| 142 | # dict args |
| 143 | data_dict = [{"data": i} for i in range(10)] |
| 144 | cursor.executemany("insert into test (data) values (%(data)s)", data_dict) |
| 145 | self.assertTrue( |
| 146 | cursor._executed.endswith(b",(7),(8),(9)"), |
| 147 | "execute many with %(data)s not in one query", |
| 148 | ) |
| 149 | |
| 150 | # %% in column set |
| 151 | cursor.execute( |
nothing calls this directly
no test coverage detected