@@ -430,9 +430,14 @@ static int check_cursor(pysqlite_Cursor* cur)
430
430
if (cur -> closed ) {
431
431
PyErr_SetString (pysqlite_ProgrammingError , "Cannot operate on a closed cursor." );
432
432
return 0 ;
433
- } else {
434
- return pysqlite_check_thread (cur -> connection ) && pysqlite_check_connection (cur -> connection );
435
433
}
434
+
435
+ if (cur -> locked ) {
436
+ PyErr_SetString (pysqlite_ProgrammingError , "Recursive use of cursors not allowed." );
437
+ return 0 ;
438
+ }
439
+
440
+ return pysqlite_check_thread (cur -> connection ) && pysqlite_check_connection (cur -> connection );
436
441
}
437
442
438
443
PyObject * _pysqlite_query_execute (pysqlite_Cursor * self , int multiple , PyObject * args )
@@ -455,9 +460,10 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
455
460
int allow_8bit_chars ;
456
461
457
462
if (!check_cursor (self )) {
458
- return NULL ;
463
+ goto error ;
459
464
}
460
465
466
+ self -> locked = 1 ;
461
467
self -> reset = 0 ;
462
468
463
469
/* Make shooting yourself in the foot with not utf-8 decodable 8-bit-strings harder */
@@ -470,12 +476,12 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
470
476
if (multiple ) {
471
477
/* executemany() */
472
478
if (!PyArg_ParseTuple (args , "OO" , & operation , & second_argument )) {
473
- return NULL ;
479
+ goto error ;
474
480
}
475
481
476
482
if (!PyUnicode_Check (operation )) {
477
483
PyErr_SetString (PyExc_ValueError , "operation parameter must be str" );
478
- return NULL ;
484
+ goto error ;
479
485
}
480
486
481
487
if (PyIter_Check (second_argument )) {
@@ -486,23 +492,23 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
486
492
/* sequence */
487
493
parameters_iter = PyObject_GetIter (second_argument );
488
494
if (!parameters_iter ) {
489
- return NULL ;
495
+ goto error ;
490
496
}
491
497
}
492
498
} else {
493
499
/* execute() */
494
500
if (!PyArg_ParseTuple (args , "O|O" , & operation , & second_argument )) {
495
- return NULL ;
501
+ goto error ;
496
502
}
497
503
498
504
if (!PyUnicode_Check (operation )) {
499
505
PyErr_SetString (PyExc_ValueError , "operation parameter must be str" );
500
- return NULL ;
506
+ goto error ;
501
507
}
502
508
503
509
parameters_list = PyList_New (0 );
504
510
if (!parameters_list ) {
505
- return NULL ;
511
+ goto error ;
506
512
}
507
513
508
514
if (second_argument == NULL ) {
@@ -742,14 +748,17 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
742
748
* ROLLBACK could have happened */
743
749
#ifdef SQLITE_VERSION_NUMBER
744
750
#if SQLITE_VERSION_NUMBER >= 3002002
745
- self -> connection -> inTransaction = !sqlite3_get_autocommit (self -> connection -> db );
751
+ if (self -> connection && self -> connection -> db )
752
+ self -> connection -> inTransaction = !sqlite3_get_autocommit (self -> connection -> db );
746
753
#endif
747
754
#endif
748
755
749
756
Py_XDECREF (parameters );
750
757
Py_XDECREF (parameters_iter );
751
758
Py_XDECREF (parameters_list );
752
759
760
+ self -> locked = 0 ;
761
+
753
762
if (PyErr_Occurred ()) {
754
763
self -> rowcount = -1L ;
755
764
return NULL ;
0 commit comments