@@ -1159,35 +1159,31 @@ pysqlite_cursor_fetchone_impl(pysqlite_Cursor *self)
11591159/*[clinic input]
11601160_sqlite3.Cursor.fetchmany as pysqlite_cursor_fetchmany
11611161
1162- size as maxrows: int (c_default='((pysqlite_Cursor *)self)->arraysize') = 1
1162+ size as maxrows: uint32 (c_default='((pysqlite_Cursor *)self)->arraysize') = 1
11631163 The default value is set by the Cursor.arraysize attribute.
11641164
11651165Fetches several rows from the resultset.
11661166[clinic start generated code]*/
11671167
11681168static PyObject *
1169- pysqlite_cursor_fetchmany_impl (pysqlite_Cursor * self , int maxrows )
1170- /*[clinic end generated code: output=a8ef31fea64d0906 input=035dbe44a1005bf2 ]*/
1169+ pysqlite_cursor_fetchmany_impl (pysqlite_Cursor * self , uint32_t maxrows )
1170+ /*[clinic end generated code: output=3325f2b477c71baf input=a509c412aa70b27e ]*/
11711171{
11721172 PyObject * row ;
11731173 PyObject * list ;
1174- int counter = 0 ;
11751174
11761175 list = PyList_New (0 );
11771176 if (!list ) {
11781177 return NULL ;
11791178 }
11801179
1181- while ((row = pysqlite_cursor_iternext ((PyObject * )self ))) {
1182- if (PyList_Append (list , row ) < 0 ) {
1183- Py_DECREF (row );
1184- break ;
1185- }
1180+ while (maxrows > 0 && (row = pysqlite_cursor_iternext ((PyObject * )self ))) {
1181+ int rc = PyList_Append (list , row );
11861182 Py_DECREF (row );
1187-
1188- if (++ counter == maxrows ) {
1183+ if (rc < 0 ) {
11891184 break ;
11901185 }
1186+ maxrows -- ;
11911187 }
11921188
11931189 if (PyErr_Occurred ()) {
@@ -1301,6 +1297,30 @@ pysqlite_cursor_close_impl(pysqlite_Cursor *self)
13011297 Py_RETURN_NONE ;
13021298}
13031299
1300+ /*[clinic input]
1301+ @getter
1302+ _sqlite3.Cursor.arraysize
1303+ [clinic start generated code]*/
1304+
1305+ static PyObject *
1306+ _sqlite3_Cursor_arraysize_get_impl (pysqlite_Cursor * self )
1307+ /*[clinic end generated code: output=e0919d97175e6c50 input=3278f8d3ecbd90e3]*/
1308+ {
1309+ return PyLong_FromUInt32 (self -> arraysize );
1310+ }
1311+
1312+ /*[clinic input]
1313+ @setter
1314+ _sqlite3.Cursor.arraysize
1315+ [clinic start generated code]*/
1316+
1317+ static int
1318+ _sqlite3_Cursor_arraysize_set_impl (pysqlite_Cursor * self , PyObject * value )
1319+ /*[clinic end generated code: output=af59a6b09f8cce6e input=ace48cb114e26060]*/
1320+ {
1321+ return PyLong_AsUInt32 (value , & self -> arraysize );
1322+ }
1323+
13041324static PyMethodDef cursor_methods [] = {
13051325 PYSQLITE_CURSOR_CLOSE_METHODDEF
13061326 PYSQLITE_CURSOR_EXECUTEMANY_METHODDEF
@@ -1318,14 +1338,18 @@ static struct PyMemberDef cursor_members[] =
13181338{
13191339 {"connection" , _Py_T_OBJECT , offsetof(pysqlite_Cursor , connection ), Py_READONLY },
13201340 {"description" , _Py_T_OBJECT , offsetof(pysqlite_Cursor , description ), Py_READONLY },
1321- {"arraysize" , Py_T_INT , offsetof(pysqlite_Cursor , arraysize ), 0 },
13221341 {"lastrowid" , _Py_T_OBJECT , offsetof(pysqlite_Cursor , lastrowid ), Py_READONLY },
13231342 {"rowcount" , Py_T_LONG , offsetof(pysqlite_Cursor , rowcount ), Py_READONLY },
13241343 {"row_factory" , _Py_T_OBJECT , offsetof(pysqlite_Cursor , row_factory ), 0 },
13251344 {"__weaklistoffset__" , Py_T_PYSSIZET , offsetof(pysqlite_Cursor , in_weakreflist ), Py_READONLY },
13261345 {NULL }
13271346};
13281347
1348+ static struct PyGetSetDef cursor_getsets [] = {
1349+ _SQLITE3_CURSOR_ARRAYSIZE_GETSETDEF
1350+ {NULL },
1351+ };
1352+
13291353static const char cursor_doc [] =
13301354PyDoc_STR ("SQLite database cursor class." );
13311355
@@ -1336,6 +1360,7 @@ static PyType_Slot cursor_slots[] = {
13361360 {Py_tp_iternext , pysqlite_cursor_iternext },
13371361 {Py_tp_methods , cursor_methods },
13381362 {Py_tp_members , cursor_members },
1363+ {Py_tp_getset , cursor_getsets },
13391364 {Py_tp_init , pysqlite_cursor_init },
13401365 {Py_tp_traverse , cursor_traverse },
13411366 {Py_tp_clear , cursor_clear },
0 commit comments