Skip to content

Commit accceee

Browse files
committed
Restore Backup destructor & small style changes
1 parent 11f33af commit accceee

File tree

8 files changed

+96
-30
lines changed

8 files changed

+96
-30
lines changed

include/SQLiteCpp/Backup.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ class Backup
9696
Backup(const Backup&) = delete;
9797
Backup& operator=(const Backup&) = delete;
9898

99+
/// Release the SQLite Backup resource.
100+
~Backup();
101+
99102
/**
100103
* @brief Execute a step of backup with a given number of source pages to be copied
101104
*
@@ -118,13 +121,7 @@ class Backup
118121
int getTotalPageCount() const;
119122

120123
private:
121-
// Deleter functor to use with smart pointers to close the SQLite database backup in an RAII fashion.
122-
struct Deleter
123-
{
124-
void operator()(sqlite3_backup* apBackup);
125-
};
126-
127-
std::unique_ptr<sqlite3_backup, Deleter> mpSQLiteBackup{}; ///< Pointer to SQLite Database Backup Handle
124+
sqlite3_backup* mpSQLiteBackup = nullptr; ///< Pointer to SQLite Database Backup Handle
128125
};
129126

130127
} // namespace SQLite

include/SQLiteCpp/Column.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ class Column
5656
*/
5757
explicit Column(const Statement::TStatementPtr& aStmtPtr, int aIndex);
5858

59-
// default destructor: the finalization will be done by the destructor of the last shared pointer
60-
// default copy constructor and assignment operator are perfectly suited :
61-
// they copy the Statement::Ptr which in turn increments the reference counter.
62-
6359
/**
6460
* @brief Return a pointer to the named assigned to this result column (potentially aliased)
6561
*

include/SQLiteCpp/Row.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* @file Row.h
3+
* @ingroup SQLiteCpp
4+
* @brief TODO:
5+
*
6+
* Copyright (c) 2015 Shibao HONG ([email protected])
7+
* Copyright (c) 2015-2021 Sebastien Rombauts ([email protected])
8+
*
9+
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
10+
* or copy at http://opensource.org/licenses/MIT)
11+
*/
12+
#pragma once
13+
14+
#include <SQLiteCpp/RowExecutor.h>
15+
16+
#include <string>
17+
18+
// Forward declaration to avoid inclusion of <sqlite3.h> in a header
19+
struct sqlite3_stmt;
20+
class Row;
21+
22+
namespace SQLite
23+
{
24+
25+
26+
class Row
27+
{
28+
public:
29+
Row(RowExecutor::TRowPtr apRow, std::size_t aID);
30+
31+
/**
32+
* @brief Test if the column value is NULL
33+
*
34+
* @param[in] aIndex Index of the column, starting at 0
35+
*
36+
* @return true if the column value is NULL
37+
*
38+
* Throw an exception if the specified index is out of the [0, getColumnCount()) range.
39+
*/
40+
bool isColumnNull(const int aIndex) const;
41+
42+
private:
43+
RowExecutor::TRowWeakPtr mpRow;
44+
std::size_t ID;
45+
};
46+
47+
} // namespace SQLite

include/SQLiteCpp/Savepoint.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,6 @@ class Savepoint {
9090
private:
9191
Database& mDatabase; ///< Reference to the SQLite Database Connection
9292
std::string msName; ///< Name of the Savepoint
93-
bool mbReleased{ false }; ///< True when release has been called
93+
bool mbReleased = false; ///< True when release has been called
9494
};
9595
} // namespace SQLite

include/SQLiteCpp/Statement.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -698,12 +698,12 @@ class Statement
698698
std::string mQuery; //!< UTF-8 SQL Query
699699
sqlite3* mpSQLite; //!< Pointer to SQLite Database Connection Handle
700700
TStatementPtr mpPreparedStatement; //!< Shared Pointer to the prepared SQLite Statement Object
701-
int mColumnCount{0}; //!< Number of columns in the result of the prepared statement
702-
bool mbHasRow{false}; //!< true when a row has been fetched with executeStep()
703-
bool mbDone{false}; //!< true when the last executeStep() had no more row to fetch
701+
int mColumnCount = 0; //!< Number of columns in the result of the prepared statement
702+
bool mbHasRow = false; //!< true when a row has been fetched with executeStep()
703+
bool mbDone = false; //!< true when the last executeStep() had no more row to fetch
704704

705705
/// Map of columns index by name (mutable so getColumnIndex can be const)
706-
mutable std::map<std::string, int, std::less<>> mColumnNames{};
706+
mutable std::map<std::string, int, std::less<>> mColumnNames;
707707
};
708708

709709

include/SQLiteCpp/Transaction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class Transaction
8888

8989
private:
9090
Database& mDatabase; ///< Reference to the SQLite Database Connection
91-
bool mbCommited{ false }; ///< True when commit has been called
91+
bool mbCommited = false; ///< True when commit has been called
9292
};
9393

9494

src/Backup.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ Backup::Backup(Database& aDestDatabase,
2424
Database& aSrcDatabase,
2525
const char* apSrcDatabaseName)
2626
{
27-
mpSQLiteBackup.reset(sqlite3_backup_init(aDestDatabase.getHandle(),
27+
mpSQLiteBackup = 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,10 +48,19 @@ 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+
5160
// Execute backup step with a given number of source pages to be copied
5261
int Backup::executeStep(const int aNumPage /* = -1 */)
5362
{
54-
const int res = sqlite3_backup_step(mpSQLiteBackup.get(), aNumPage);
63+
const int res = sqlite3_backup_step(mpSQLiteBackup, aNumPage);
5564
if (SQLITE_OK != res && SQLITE_DONE != res && SQLITE_BUSY != res && SQLITE_LOCKED != res)
5665
{
5766
throw SQLite::Exception(sqlite3_errstr(res), res);
@@ -62,22 +71,14 @@ int Backup::executeStep(const int aNumPage /* = -1 */)
6271
// Get the number of remaining source pages to be copied in this backup process
6372
int Backup::getRemainingPageCount() const
6473
{
65-
return sqlite3_backup_remaining(mpSQLiteBackup.get());
74+
return sqlite3_backup_remaining(mpSQLiteBackup);
6675
}
6776

6877
// Get the number of total source pages to be copied in this backup process
6978
int Backup::getTotalPageCount() const
7079
{
71-
return sqlite3_backup_pagecount(mpSQLiteBackup.get());
80+
return sqlite3_backup_pagecount(mpSQLiteBackup);
7281
}
7382

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-
}
8283

8384
} // namespace SQLite

src/Row.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @file Row.cpp
3+
* @ingroup SQLiteCpp
4+
* @brief TODO:
5+
*
6+
* Copyright (c) 2015 Shibao HONG ([email protected])
7+
* Copyright (c) 2015-2021 Sebastien Rombauts ([email protected])
8+
*
9+
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
10+
* or copy at http://opensource.org/licenses/MIT)
11+
*/
12+
#include <SQLiteCpp/Row.h>
13+
14+
#include <SQLiteCpp/Exception.h>
15+
16+
#include <sqlite3.h>
17+
18+
namespace SQLite
19+
{
20+
21+
22+
;
23+
24+
25+
} // namespace SQLite

0 commit comments

Comments
 (0)