| 137 | |
| 138 | |
| 139 | def _test_dbapi_raw(n, connect): |
| 140 | compiled = ( |
| 141 | Customer.__table__.insert() |
| 142 | .values(name=bindparam("name"), description=bindparam("description")) |
| 143 | .compile(dialect=engine.dialect) |
| 144 | ) |
| 145 | |
| 146 | if compiled.positional: |
| 147 | args = ( |
| 148 | ("customer name %d" % i, "customer description %d" % i) |
| 149 | for i in range(n) |
| 150 | ) |
| 151 | else: |
| 152 | args = ( |
| 153 | dict( |
| 154 | name="customer name %d" % i, |
| 155 | description="customer description %d" % i, |
| 156 | ) |
| 157 | for i in range(n) |
| 158 | ) |
| 159 | sql = str(compiled) |
| 160 | |
| 161 | if connect: |
| 162 | for arg in args: |
| 163 | # there's no connection pool, so if these were distinct |
| 164 | # calls, we'd be connecting each time |
| 165 | conn = engine.pool._creator() |
| 166 | cursor = conn.cursor() |
| 167 | cursor.execute(sql, arg) |
| 168 | cursor.lastrowid |
| 169 | conn.commit() |
| 170 | conn.close() |
| 171 | else: |
| 172 | for arg in args: |
| 173 | conn = engine.raw_connection() |
| 174 | cursor = conn.cursor() |
| 175 | cursor.execute(sql, arg) |
| 176 | cursor.lastrowid |
| 177 | conn.commit() |
| 178 | conn.close() |
| 179 | |
| 180 | |
| 181 | if __name__ == "__main__": |