|
1 | 1 | import pytest |
2 | 2 | import MySQLdb.cursors |
| 3 | +from MySQLdb.constants import ER |
3 | 4 | from configdb import connection_factory |
4 | 5 |
|
5 | 6 |
|
@@ -243,3 +244,43 @@ def test_binary_prefix(): |
243 | 244 | "INSERT INTO test_binary_prefix (id, json) VALUES (%(id)s, %(json)s)", |
244 | 245 | ({"id": 1, "json": "{}"}, {"id": 2, "json": "{}"}), |
245 | 246 | ) |
| 247 | + |
| 248 | + |
| 249 | +def test_warning_count(): |
| 250 | + conn = connect() |
| 251 | + cursor = conn.cursor() |
| 252 | + |
| 253 | + cursor.execute("DROP TABLE IF EXISTS `no_exists_table`") |
| 254 | + assert cursor.warning_count == 1 |
| 255 | + |
| 256 | + cursor.execute("SHOW WARNINGS") |
| 257 | + warning = cursor.fetchone() |
| 258 | + assert warning[1] == ER.BAD_TABLE_ERROR |
| 259 | + assert "no_exists_table" in warning[2] |
| 260 | + |
| 261 | + cursor.execute("SELECT 1") |
| 262 | + assert cursor.warning_count == 0 |
| 263 | + |
| 264 | + |
| 265 | +def test_sscursor_warning_count(): |
| 266 | + conn = connect() |
| 267 | + cursor = conn.cursor(MySQLdb.cursors.SSCursor) |
| 268 | + |
| 269 | + cursor.execute("DROP TABLE IF EXISTS `no_exists_table`") |
| 270 | + assert cursor.warning_count == 1 |
| 271 | + |
| 272 | + cursor.execute("SHOW WARNINGS") |
| 273 | + warning = cursor.fetchone() |
| 274 | + assert warning[1] == ER.BAD_TABLE_ERROR |
| 275 | + assert "no_exists_table" in warning[2] |
| 276 | + assert cursor.fetchone() is None |
| 277 | + |
| 278 | + cursor.execute("SELECT 1") |
| 279 | + assert cursor.fetchone() == (1,) |
| 280 | + assert cursor.fetchone() is None |
| 281 | + assert cursor.warning_count == 0 |
| 282 | + |
| 283 | + cursor.execute("SELECT CAST('abc' AS SIGNED)") |
| 284 | + rows = cursor.fetchmany(2) |
| 285 | + assert len(rows) == 1 |
| 286 | + assert cursor.warning_count == 1 |
0 commit comments