@@ -107,7 +107,6 @@ pysqlite_cursor_init_impl(pysqlite_Cursor *self,
107
107
108
108
self -> arraysize = 1 ;
109
109
self -> closed = 0 ;
110
- self -> rowcount = -1L ;
111
110
112
111
Py_INCREF (Py_None );
113
112
Py_XSETREF (self -> row_factory , Py_None );
@@ -835,10 +834,9 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
835
834
stmt_reset (self -> statement );
836
835
}
837
836
838
- /* reset description and rowcount */
837
+ /* reset description */
839
838
Py_INCREF (Py_None );
840
839
Py_SETREF (self -> description , Py_None );
841
- self -> rowcount = 0L ;
842
840
843
841
if (self -> statement ) {
844
842
(void )stmt_reset (self -> statement );
@@ -944,12 +942,6 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
944
942
}
945
943
}
946
944
947
- if (self -> statement -> is_dml ) {
948
- self -> rowcount += (long )sqlite3_changes (self -> connection -> db );
949
- } else {
950
- self -> rowcount = -1L ;
951
- }
952
-
953
945
if (rc == SQLITE_DONE && !multiple ) {
954
946
stmt_reset (self -> statement );
955
947
Py_CLEAR (self -> statement );
@@ -980,7 +972,6 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
980
972
self -> locked = 0 ;
981
973
982
974
if (PyErr_Occurred ()) {
983
- self -> rowcount = -1L ;
984
975
return NULL ;
985
976
} else {
986
977
return Py_NewRef ((PyObject * )self );
@@ -1321,13 +1312,27 @@ static PyMethodDef cursor_methods[] = {
1321
1312
{NULL , NULL }
1322
1313
};
1323
1314
1315
+ static PyObject *
1316
+ get_rowcount (pysqlite_Cursor * self , void * Py_UNUSED (unused ))
1317
+ {
1318
+ if (!check_cursor (self )) {
1319
+ return NULL ;
1320
+ }
1321
+ int changes = sqlite3_changes (self -> connection -> db );
1322
+ return PyLong_FromLong (changes );
1323
+ }
1324
+
1325
+ static PyGetSetDef cursor_getset [] = {
1326
+ {"rowcount" , (getter )get_rowcount , (setter )NULL },
1327
+ {NULL },
1328
+ };
1329
+
1324
1330
static struct PyMemberDef cursor_members [] =
1325
1331
{
1326
1332
{"connection" , T_OBJECT , offsetof(pysqlite_Cursor , connection ), READONLY },
1327
1333
{"description" , T_OBJECT , offsetof(pysqlite_Cursor , description ), READONLY },
1328
1334
{"arraysize" , T_INT , offsetof(pysqlite_Cursor , arraysize ), 0 },
1329
1335
{"lastrowid" , T_OBJECT , offsetof(pysqlite_Cursor , lastrowid ), READONLY },
1330
- {"rowcount" , T_LONG , offsetof(pysqlite_Cursor , rowcount ), READONLY },
1331
1336
{"row_factory" , T_OBJECT , offsetof(pysqlite_Cursor , row_factory ), 0 },
1332
1337
{"__weaklistoffset__" , T_PYSSIZET , offsetof(pysqlite_Cursor , in_weakreflist ), READONLY },
1333
1338
{NULL }
@@ -1346,6 +1351,7 @@ static PyType_Slot cursor_slots[] = {
1346
1351
{Py_tp_init , pysqlite_cursor_init },
1347
1352
{Py_tp_traverse , cursor_traverse },
1348
1353
{Py_tp_clear , cursor_clear },
1354
+ {Py_tp_getset , cursor_getset },
1349
1355
{0 , NULL },
1350
1356
};
1351
1357
0 commit comments