mirror of
https://github.com/mariadb-corporation/mariadb-connector-python.git
synced 2025-08-11 02:43:15 +00:00
Fix for CONPY-225:
Set value for affected_rows.
This commit is contained in:
@ -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);
|
||||
|
||||
|
@ -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:
|
||||
|
Reference in New Issue
Block a user