@@ -24,10 +24,10 @@ Backup::Backup(Database& aDestDatabase,
24
24
Database& aSrcDatabase,
25
25
const char * apSrcDatabaseName)
26
26
{
27
- mpSQLiteBackup = sqlite3_backup_init (aDestDatabase.getHandle (),
27
+ mpSQLiteBackup. reset ( sqlite3_backup_init (aDestDatabase.getHandle (),
28
28
apDestDatabaseName,
29
29
aSrcDatabase.getHandle (),
30
- apSrcDatabaseName);
30
+ apSrcDatabaseName)) ;
31
31
if (nullptr == mpSQLiteBackup)
32
32
{
33
33
// 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) :
48
48
{
49
49
}
50
50
51
- // Release resource for SQLite database backup
52
- Backup::~Backup ()
53
- {
54
- if (mpSQLiteBackup)
55
- {
56
- sqlite3_backup_finish (mpSQLiteBackup);
57
- }
58
- }
59
-
60
51
// Execute backup step with a given number of source pages to be copied
61
52
int Backup::executeStep (const int aNumPage /* = -1 */ )
62
53
{
63
- const int res = sqlite3_backup_step (mpSQLiteBackup, aNumPage);
54
+ const int res = sqlite3_backup_step (mpSQLiteBackup. get () , aNumPage);
64
55
if (SQLITE_OK != res && SQLITE_DONE != res && SQLITE_BUSY != res && SQLITE_LOCKED != res)
65
56
{
66
57
throw SQLite::Exception (sqlite3_errstr (res), res);
@@ -71,13 +62,22 @@ int Backup::executeStep(const int aNumPage /* = -1 */)
71
62
// Get the number of remaining source pages to be copied in this backup process
72
63
int Backup::getRemainingPageCount () const
73
64
{
74
- return sqlite3_backup_remaining (mpSQLiteBackup);
65
+ return sqlite3_backup_remaining (mpSQLiteBackup. get () );
75
66
}
76
67
77
68
// Get the number of total source pages to be copied in this backup process
78
69
int Backup::getTotalPageCount () const
79
70
{
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
+ }
81
81
}
82
82
83
83
0 commit comments