@@ -24,10 +24,10 @@ Backup::Backup(Database& aDestDatabase,
2424 Database& aSrcDatabase,
2525 const char * apSrcDatabaseName)
2626{
27- mpSQLiteBackup = sqlite3_backup_init (aDestDatabase.getHandle (),
27+ mpSQLiteBackup. reset ( sqlite3_backup_init (aDestDatabase.getHandle (),
2828 apDestDatabaseName,
2929 aSrcDatabase.getHandle (),
30- apSrcDatabaseName);
30+ apSrcDatabaseName)) ;
3131 if (nullptr == mpSQLiteBackup)
3232 {
3333 // If an error occurs, the error code and message are attached to the destination database connection.
@@ -48,19 +48,10 @@ Backup::Backup(Database &aDestDatabase, Database &aSrcDatabase) :
4848{
4949}
5050
51- // Release resource for SQLite database backup
52- Backup::~Backup ()
53- {
54- if (mpSQLiteBackup)
55- {
56- sqlite3_backup_finish (mpSQLiteBackup);
57- }
58- }
59-
6051// Execute backup step with a given number of source pages to be copied
6152int Backup::executeStep (const int aNumPage /* = -1 */ )
6253{
63- const int res = sqlite3_backup_step (mpSQLiteBackup, aNumPage);
54+ const int res = sqlite3_backup_step (mpSQLiteBackup. get () , aNumPage);
6455 if (SQLITE_OK != res && SQLITE_DONE != res && SQLITE_BUSY != res && SQLITE_LOCKED != res)
6556 {
6657 throw SQLite::Exception (sqlite3_errstr (res), res);
@@ -69,15 +60,24 @@ int Backup::executeStep(const int aNumPage /* = -1 */)
6960}
7061
7162// Get the number of remaining source pages to be copied in this backup process
72- int Backup::getRemainingPageCount ()
63+ int Backup::getRemainingPageCount () const
7364{
74- return sqlite3_backup_remaining (mpSQLiteBackup);
65+ return sqlite3_backup_remaining (mpSQLiteBackup. get () );
7566}
7667
7768// Get the number of total source pages to be copied in this backup process
78- int Backup::getTotalPageCount ()
69+ int Backup::getTotalPageCount () const
7970{
80- return sqlite3_backup_pagecount (mpSQLiteBackup);
71+ return sqlite3_backup_pagecount (mpSQLiteBackup.get ());
72+ }
73+
74+ // Release resource for SQLite database backup
75+ void SQLite::Backup::Deleter::operator ()(sqlite3_backup* apBackup)
76+ {
77+ if (apBackup)
78+ {
79+ sqlite3_backup_finish (apBackup);
80+ }
8181}
8282
8383} // namespace SQLite
0 commit comments