@@ -459,43 +459,29 @@ static PyObject *
459459pysqlite_connection_commit_impl (pysqlite_Connection * self )
460460/*[clinic end generated code: output=3da45579e89407f2 input=39c12c04dda276a8]*/
461461{
462- int rc ;
463- sqlite3_stmt * statement ;
464-
465462 if (!pysqlite_check_thread (self ) || !pysqlite_check_connection (self )) {
466463 return NULL ;
467464 }
468465
469466 if (!sqlite3_get_autocommit (self -> db )) {
467+ int rc ;
470468
471469 Py_BEGIN_ALLOW_THREADS
470+ sqlite3_stmt * statement ;
472471 rc = sqlite3_prepare_v2 (self -> db , "COMMIT" , 7 , & statement , NULL );
473- Py_END_ALLOW_THREADS
474- if (rc != SQLITE_OK ) {
475- _pysqlite_seterror (self -> state , self -> db );
476- goto error ;
472+ if (rc == SQLITE_OK ) {
473+ (void )sqlite3_step (statement );
474+ rc = sqlite3_finalize (statement );
477475 }
478-
479- rc = pysqlite_step (statement );
480- if (rc != SQLITE_DONE ) {
481- _pysqlite_seterror (self -> state , self -> db );
482- }
483-
484- Py_BEGIN_ALLOW_THREADS
485- rc = sqlite3_finalize (statement );
486476 Py_END_ALLOW_THREADS
487- if (rc != SQLITE_OK && !PyErr_Occurred ()) {
488- _pysqlite_seterror (self -> state , self -> db );
489- }
490477
478+ if (rc != SQLITE_OK ) {
479+ (void )_pysqlite_seterror (self -> state , self -> db );
480+ return NULL ;
481+ }
491482 }
492483
493- error :
494- if (PyErr_Occurred ()) {
495- return NULL ;
496- } else {
497- Py_RETURN_NONE ;
498- }
484+ Py_RETURN_NONE ;
499485}
500486
501487/*[clinic input]
@@ -508,44 +494,32 @@ static PyObject *
508494pysqlite_connection_rollback_impl (pysqlite_Connection * self )
509495/*[clinic end generated code: output=b66fa0d43e7ef305 input=12d4e8d068942830]*/
510496{
511- int rc ;
512- sqlite3_stmt * statement ;
513-
514497 if (!pysqlite_check_thread (self ) || !pysqlite_check_connection (self )) {
515498 return NULL ;
516499 }
517500
518501 if (!sqlite3_get_autocommit (self -> db )) {
519502 pysqlite_do_all_statements (self );
520503
504+ int rc ;
505+
521506 Py_BEGIN_ALLOW_THREADS
507+ sqlite3_stmt * statement ;
522508 rc = sqlite3_prepare_v2 (self -> db , "ROLLBACK" , 9 , & statement , NULL );
523- Py_END_ALLOW_THREADS
524- if (rc != SQLITE_OK ) {
525- _pysqlite_seterror (self -> state , self -> db );
526- goto error ;
527- }
528-
529- rc = pysqlite_step (statement );
530- if (rc != SQLITE_DONE ) {
531- _pysqlite_seterror (self -> state , self -> db );
509+ if (rc == SQLITE_OK ) {
510+ (void )sqlite3_step (statement );
511+ rc = sqlite3_finalize (statement );
532512 }
533-
534- Py_BEGIN_ALLOW_THREADS
535- rc = sqlite3_finalize (statement );
536513 Py_END_ALLOW_THREADS
537- if (rc != SQLITE_OK && !PyErr_Occurred ()) {
538- _pysqlite_seterror (self -> state , self -> db );
514+
515+ if (rc != SQLITE_OK ) {
516+ (void )_pysqlite_seterror (self -> state , self -> db );
517+ return NULL ;
539518 }
540519
541520 }
542521
543- error :
544- if (PyErr_Occurred ()) {
545- return NULL ;
546- } else {
547- Py_RETURN_NONE ;
548- }
522+ Py_RETURN_NONE ;
549523}
550524
551525static int
0 commit comments