Fix for CONPY-225:

Set value for affected_rows.
This commit is contained in:
Georg Richter
2022-10-07 08:47:48 +02:00
parent 37ea27cf86
commit d70be504e3
2 changed files with 22 additions and 2 deletions

View File

@ -236,7 +236,7 @@ static struct PyMemberDef MrdbCursor_Members[] =
T_ULONGLONG,
offsetof(MrdbCursor, affected_rows),
READONLY,
"Number of affected rows"},
"This property is deprecated - use rowcount instead."},
{"_rownumber",
T_ULONGLONG,
offsetof(MrdbCursor, row_number),
@ -646,8 +646,9 @@ PyObject *MrdbCursor_InitResultSet(MrdbCursor *self)
if (self->field_count)
{
self->row_count= CURSOR_NUM_ROWS(self);
self->affected_rows= 0;
} else {
self->row_count= CURSOR_AFFECTED_ROWS(self);
self->row_count= self->affected_rows= CURSOR_AFFECTED_ROWS(self);
}
self->lastrow_id= CURSOR_INSERT_ID(self);

View File

@ -1465,6 +1465,25 @@ class TestCursor(unittest.TestCase):
del cursor
def test_conpy225(self):
conn = create_connection()
cursor = conn.cursor()
cursor.execute("CREATE TEMPORARY TABLE x01 (a int, b int)")
params = ((1, 2), (2, 3), (3, 4), (4, 5))
cursor.executemany("INSERT INTO x01 VALUES (?,?)", params)
self.assertEqual(cursor.rowcount, 4)
self.assertEqual(cursor.affected_rows, 4)
cursor.execute("UPDATE x01 SET a=1 WHERE a=1")
self.assertEqual(cursor.rowcount, 0)
self.assertEqual(cursor.affected_rows, 0)
cursor.execute("UPDATE x01 SET a=1 WHERE a=4")
self.assertEqual(cursor.affected_rows, 1)
self.assertEqual(cursor.rowcount, 1)
def test_conpy91(self):
with create_connection() as connection:
with connection.cursor() as cursor: