|
| 1 | +""" |
| 2 | +Integration tests for client.execute() DML row count reporting. |
| 3 | +
|
| 4 | +Verifies that execute() correctly returns the number of rows |
| 5 | +affected by INSERT, UPDATE, and DELETE statements. |
| 6 | +""" |
| 7 | + |
| 8 | +from altertable_flightsql import Client |
| 9 | +from tests.conftest import TableInfo |
| 10 | + |
| 11 | + |
| 12 | +class TestExecuteRowCount: |
| 13 | + """Test that execute() returns the correct number of affected rows.""" |
| 14 | + |
| 15 | + def test_insert_returns_row_count(self, altertable_client: Client, test_table: TableInfo): |
| 16 | + """Test that INSERT returns the number of inserted rows.""" |
| 17 | + rows = altertable_client.execute( |
| 18 | + f"INSERT INTO {test_table.full_name} (id, name, value) VALUES (4, 'Dave', 400), (5, 'Eve', 500)" |
| 19 | + ) |
| 20 | + assert rows == 2 |
| 21 | + |
| 22 | + def test_update_returns_row_count(self, altertable_client: Client, test_table: TableInfo): |
| 23 | + """Test that UPDATE returns the number of updated rows.""" |
| 24 | + rows = altertable_client.execute( |
| 25 | + f"UPDATE {test_table.full_name} SET value = 999 WHERE value >= 200" |
| 26 | + ) |
| 27 | + assert rows == 2 |
| 28 | + |
| 29 | + def test_delete_returns_row_count(self, altertable_client: Client, test_table: TableInfo): |
| 30 | + """Test that DELETE returns the number of deleted rows.""" |
| 31 | + rows = altertable_client.execute(f"DELETE FROM {test_table.full_name} WHERE id IN (1, 2)") |
| 32 | + assert rows == 2 |
| 33 | + |
| 34 | + def test_delete_no_match_returns_zero(self, altertable_client: Client, test_table: TableInfo): |
| 35 | + """Test that DELETE with no matching rows returns 0.""" |
| 36 | + rows = altertable_client.execute(f"DELETE FROM {test_table.full_name} WHERE id = 9999") |
| 37 | + assert rows == 0 |
| 38 | + |
| 39 | + def test_update_no_match_returns_zero(self, altertable_client: Client, test_table: TableInfo): |
| 40 | + """Test that UPDATE with no matching rows returns 0.""" |
| 41 | + rows = altertable_client.execute( |
| 42 | + f"UPDATE {test_table.full_name} SET value = 0 WHERE id = 9999" |
| 43 | + ) |
| 44 | + assert rows == 0 |
0 commit comments