@@ -396,43 +396,29 @@ static PyObject *
396396pysqlite_connection_commit_impl (pysqlite_Connection * self )
397397/*[clinic end generated code: output=3da45579e89407f2 input=39c12c04dda276a8]*/
398398{
399- int rc ;
400- sqlite3_stmt * statement ;
401-
402399 if (!pysqlite_check_thread (self ) || !pysqlite_check_connection (self )) {
403400 return NULL ;
404401 }
405402
406403 if (!sqlite3_get_autocommit (self -> db )) {
404+ int rc ;
407405
408406 Py_BEGIN_ALLOW_THREADS
407+ sqlite3_stmt * statement ;
409408 rc = sqlite3_prepare_v2 (self -> db , "COMMIT" , 7 , & statement , NULL );
410- Py_END_ALLOW_THREADS
411- if (rc != SQLITE_OK ) {
412- _pysqlite_seterror (self -> state , self -> db );
413- goto error ;
409+ if (rc == SQLITE_OK ) {
410+ (void )sqlite3_step (statement );
411+ rc = sqlite3_finalize (statement );
414412 }
415-
416- rc = pysqlite_step (statement );
417- if (rc != SQLITE_DONE ) {
418- _pysqlite_seterror (self -> state , self -> db );
419- }
420-
421- Py_BEGIN_ALLOW_THREADS
422- rc = sqlite3_finalize (statement );
423413 Py_END_ALLOW_THREADS
424- if (rc != SQLITE_OK && !PyErr_Occurred ()) {
425- _pysqlite_seterror (self -> state , self -> db );
426- }
427414
415+ if (rc != SQLITE_OK ) {
416+ (void )_pysqlite_seterror (self -> state , self -> db );
417+ return NULL ;
418+ }
428419 }
429420
430- error :
431- if (PyErr_Occurred ()) {
432- return NULL ;
433- } else {
434- Py_RETURN_NONE ;
435- }
421+ Py_RETURN_NONE ;
436422}
437423
438424/*[clinic input]
@@ -445,44 +431,32 @@ static PyObject *
445431pysqlite_connection_rollback_impl (pysqlite_Connection * self )
446432/*[clinic end generated code: output=b66fa0d43e7ef305 input=12d4e8d068942830]*/
447433{
448- int rc ;
449- sqlite3_stmt * statement ;
450-
451434 if (!pysqlite_check_thread (self ) || !pysqlite_check_connection (self )) {
452435 return NULL ;
453436 }
454437
455438 if (!sqlite3_get_autocommit (self -> db )) {
456439 pysqlite_do_all_statements (self );
457440
441+ int rc ;
442+
458443 Py_BEGIN_ALLOW_THREADS
444+ sqlite3_stmt * statement ;
459445 rc = sqlite3_prepare_v2 (self -> db , "ROLLBACK" , 9 , & statement , NULL );
460- Py_END_ALLOW_THREADS
461- if (rc != SQLITE_OK ) {
462- _pysqlite_seterror (self -> state , self -> db );
463- goto error ;
464- }
465-
466- rc = pysqlite_step (statement );
467- if (rc != SQLITE_DONE ) {
468- _pysqlite_seterror (self -> state , self -> db );
446+ if (rc == SQLITE_OK ) {
447+ (void )sqlite3_step (statement );
448+ rc = sqlite3_finalize (statement );
469449 }
470-
471- Py_BEGIN_ALLOW_THREADS
472- rc = sqlite3_finalize (statement );
473450 Py_END_ALLOW_THREADS
474- if (rc != SQLITE_OK && !PyErr_Occurred ()) {
475- _pysqlite_seterror (self -> state , self -> db );
451+
452+ if (rc != SQLITE_OK ) {
453+ (void )_pysqlite_seterror (self -> state , self -> db );
454+ return NULL ;
476455 }
477456
478457 }
479458
480- error :
481- if (PyErr_Occurred ()) {
482- return NULL ;
483- } else {
484- Py_RETURN_NONE ;
485- }
459+ Py_RETURN_NONE ;
486460}
487461
488462static int
0 commit comments