@@ -1601,7 +1601,6 @@ pysqlite_connection_backup_impl(pysqlite_Connection *self,
1601
1601
/*[clinic end generated code: output=306a3e6a38c36334 input=30ae45fc420bfd3b]*/
1602
1602
{
1603
1603
int rc ;
1604
- int callback_error = 0 ;
1605
1604
int sleep_ms = (int )(sleep * 1000.0 );
1606
1605
sqlite3 * bck_conn ;
1607
1606
sqlite3_backup * bck_handle ;
@@ -1643,60 +1642,50 @@ pysqlite_connection_backup_impl(pysqlite_Connection *self,
1643
1642
bck_handle = sqlite3_backup_init (bck_conn , "main" , self -> db , name );
1644
1643
Py_END_ALLOW_THREADS
1645
1644
1646
- if (bck_handle ) {
1647
- do {
1648
- Py_BEGIN_ALLOW_THREADS
1649
- rc = sqlite3_backup_step (bck_handle , pages );
1650
- Py_END_ALLOW_THREADS
1645
+ if (bck_handle == NULL) {
1646
+ _pysqlite_seterror (bck_conn , NULL );
1647
+ return NULL ;
1648
+ }
1651
1649
1652
- if (progress != Py_None ) {
1653
- PyObject * res ;
1654
-
1655
- res = PyObject_CallFunction (progress , "iii" , rc ,
1656
- sqlite3_backup_remaining (bck_handle ),
1657
- sqlite3_backup_pagecount (bck_handle ));
1658
- if (res == NULL ) {
1659
- /* User's callback raised an error: interrupt the loop and
1660
- propagate it. */
1661
- callback_error = 1 ;
1662
- rc = -1 ;
1663
- } else {
1664
- Py_DECREF (res );
1665
- }
1666
- }
1650
+ do {
1651
+ Py_BEGIN_ALLOW_THREADS
1652
+ rc = sqlite3_backup_step (bck_handle , pages );
1653
+ Py_END_ALLOW_THREADS
1667
1654
1668
- /* Sleep for a while if there are still further pages to copy and
1669
- the engine could not make any progress */
1670
- if (rc == SQLITE_BUSY || rc == SQLITE_LOCKED ) {
1655
+ if (progress != Py_None ) {
1656
+ int remaining = sqlite3_backup_remaining (bck_handle );
1657
+ int pagecount = sqlite3_backup_pagecount (bck_handle );
1658
+ PyObject * res = PyObject_CallFunction (progress , "iii" , rc ,
1659
+ remaining , pagecount );
1660
+ if (res == NULL ) {
1661
+ /* Callback failed: abort backup and bail. */
1671
1662
Py_BEGIN_ALLOW_THREADS
1672
- sqlite3_sleep ( sleep_ms );
1663
+ sqlite3_backup_finish ( bck_handle );
1673
1664
Py_END_ALLOW_THREADS
1665
+ return NULL ;
1674
1666
}
1675
- } while (rc == SQLITE_OK || rc == SQLITE_BUSY || rc == SQLITE_LOCKED );
1676
-
1677
- Py_BEGIN_ALLOW_THREADS
1678
- rc = sqlite3_backup_finish (bck_handle );
1679
- Py_END_ALLOW_THREADS
1680
- } else {
1681
- rc = _pysqlite_seterror (bck_conn , NULL );
1682
- }
1667
+ Py_DECREF (res );
1668
+ }
1683
1669
1684
- if (!callback_error && rc != SQLITE_OK ) {
1685
- /* We cannot use _pysqlite_seterror() here because the backup APIs do
1686
- not set the error status on the connection object, but rather on
1687
- the backup handle. */
1688
- if (rc == SQLITE_NOMEM ) {
1689
- (void )PyErr_NoMemory ();
1690
- } else {
1691
- PyErr_SetString (pysqlite_OperationalError , sqlite3_errstr (rc ));
1670
+ /* Sleep for a while if there are still further pages to copy and
1671
+ the engine could not make any progress */
1672
+ if (rc == SQLITE_BUSY || rc == SQLITE_LOCKED ) {
1673
+ Py_BEGIN_ALLOW_THREADS
1674
+ sqlite3_sleep (sleep_ms );
1675
+ Py_END_ALLOW_THREADS
1692
1676
}
1693
- }
1677
+ } while ( rc == SQLITE_OK || rc == SQLITE_BUSY || rc == SQLITE_LOCKED );
1694
1678
1695
- if (!callback_error && rc == SQLITE_OK ) {
1696
- Py_RETURN_NONE ;
1697
- } else {
1679
+ Py_BEGIN_ALLOW_THREADS
1680
+ rc = sqlite3_backup_finish (bck_handle );
1681
+ Py_END_ALLOW_THREADS
1682
+
1683
+ if (rc != SQLITE_OK ) {
1684
+ _pysqlite_seterror (bck_conn , NULL );
1698
1685
return NULL ;
1699
1686
}
1687
+
1688
+ Py_RETURN_NONE ;
1700
1689
}
1701
1690
1702
1691
/*[clinic input]
0 commit comments