summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Jamroot.jam13
-rw-r--r--libsqlitepp/sqlite-connection.cpp12
-rw-r--r--libsqlitepp/sqlite-connection.h4
-rw-r--r--libsqlitepp/sqlite-mock.cpp9
-rw-r--r--libsqlitepp/sqlite-mock.h2
-rw-r--r--libsqlitepp/sqlite-selectcommand.cpp2
-rw-r--r--libsqlitepp/unittests/Jamfile.jam1
-rw-r--r--libsqlitepp/unittests/testsqlite.cpp14
8 files changed, 26 insertions, 31 deletions
diff --git a/Jamroot.jam b/Jamroot.jam
index 61ca176..be6d230 100644
--- a/Jamroot.jam
+++ b/Jamroot.jam
@@ -6,12 +6,13 @@ variant coverage : debug ;
project
: requirements
- <variant>release:<cxxflags>"-std=c++1y -fvisibility=hidden"
- <variant>release:<linkflags>"-Wl,-z,defs,--warn-once,--gc-sections"
- <variant>debug:<cxxflags>"-W -Wall -Werror -Wwrite-strings -std=c++1y -fvisibility=hidden"
- <variant>debug:<linkflags>"-Wl,-z,defs,--warn-once"
- <variant>coverage:<cxxflags>"-W -Wall -Werror -Wwrite-strings -std=c++1y --coverage -fvisibility=hidden"
- <variant>coverage:<linkflags>"-Wl,-z,defs,--warn-once --coverage"
+ <cxxflags>"-std=c++17 -fvisibility=hidden -fvisibility-inlines-hidden"
+ <linkflags>"-Wl,-z,defs,--warn-once,--gc-sections"
+ <variant>release:<cxxflags>"-flto=2"
+ <variant>release:<linkflags>"-flto=2"
+ <variant>debug:<cxxflags>"-W -Wall -Werror -Wextra"
+ <variant>coverage:<cxxflags>"--coverage"
+ <variant>coverage:<linkflags>"--coverage"
;
build-project libsqlitepp ;
diff --git a/libsqlitepp/sqlite-connection.cpp b/libsqlitepp/sqlite-connection.cpp
index 369931d..1539668 100644
--- a/libsqlitepp/sqlite-connection.cpp
+++ b/libsqlitepp/sqlite-connection.cpp
@@ -67,16 +67,16 @@ SQLite::Connection::ping() const
}
-DB::SelectCommand *
-SQLite::Connection::newSelectCommand(const std::string & sql, const DB::CommandOptions *)
+DB::SelectCommandPtr
+SQLite::Connection::select(const std::string & sql, const DB::CommandOptionsCPtr &)
{
- return new SelectCommand(this, sql);
+ return std::make_shared<SelectCommand>(this, sql);
}
-DB::ModifyCommand *
-SQLite::Connection::newModifyCommand(const std::string & sql, const DB::CommandOptions *)
+DB::ModifyCommandPtr
+SQLite::Connection::modify(const std::string & sql, const DB::CommandOptionsCPtr &)
{
- return new ModifyCommand(this, sql);
+ return std::make_shared<ModifyCommand>(this, sql);
}
int64_t
diff --git a/libsqlitepp/sqlite-connection.h b/libsqlitepp/sqlite-connection.h
index b428b06..ba8410d 100644
--- a/libsqlitepp/sqlite-connection.h
+++ b/libsqlitepp/sqlite-connection.h
@@ -23,8 +23,8 @@ namespace SQLite {
DB::BulkDeleteStyle bulkDeleteStyle() const override;
DB::BulkUpdateStyle bulkUpdateStyle() const override;
- DB::SelectCommand * newSelectCommand(const std::string & sql, const DB::CommandOptions *) override;
- DB::ModifyCommand * newModifyCommand(const std::string & sql, const DB::CommandOptions *) override;
+ DB::SelectCommandPtr select(const std::string & sql, const DB::CommandOptionsCPtr &) override;
+ DB::ModifyCommandPtr modify(const std::string & sql, const DB::CommandOptionsCPtr &) override;
int64_t insertId() override;
diff --git a/libsqlitepp/sqlite-mock.cpp b/libsqlitepp/sqlite-mock.cpp
index 6a2edb5..418a6ac 100644
--- a/libsqlitepp/sqlite-mock.cpp
+++ b/libsqlitepp/sqlite-mock.cpp
@@ -7,8 +7,7 @@ NAMEDFACTORY("sqlite", SQLite::Mock, DB::MockDatabaseFactory);
namespace SQLite {
-Mock::Mock(const std::string & root, const std::string & name, const std::vector<boost::filesystem::path> & ss) :
- MockDatabase(name),
+Mock::Mock(const std::string & root, const std::string &, const std::vector<boost::filesystem::path> & ss) :
testDbPath(boost::filesystem::path(root) / boost::lexical_cast<std::string>(getpid()) / boost::lexical_cast<std::string>(++DB::MockDatabase::mocked))
{
CreateNewDatabase();
@@ -20,10 +19,10 @@ Mock::Mock(const std::string & name, const std::vector<boost::filesystem::path>
{
}
-DB::Connection *
+DB::ConnectionPtr
Mock::openConnection() const
{
- return new Connection(testDbPath.string());
+ return std::make_shared<Connection>(testDbPath.string());
}
Mock::~Mock()
@@ -39,7 +38,7 @@ void Mock::DropDatabase() const
void Mock::CreateNewDatabase() const
{
boost::filesystem::create_directories(testDbPath.parent_path());
- delete openConnection();
+ openConnection(); // Triggers file creation
}
}
diff --git a/libsqlitepp/sqlite-mock.h b/libsqlitepp/sqlite-mock.h
index 66ec813..4580778 100644
--- a/libsqlitepp/sqlite-mock.h
+++ b/libsqlitepp/sqlite-mock.h
@@ -17,7 +17,7 @@ class DLL_PUBLIC Mock : public DB::MockDatabase {
void DropDatabase() const override;
void CreateNewDatabase() const override;
- DB::Connection * openConnection() const override;
+ DB::ConnectionPtr openConnection() const override;
private:
const boost::filesystem::path testDbPath;
diff --git a/libsqlitepp/sqlite-selectcommand.cpp b/libsqlitepp/sqlite-selectcommand.cpp
index 0f36653..a65cbd1 100644
--- a/libsqlitepp/sqlite-selectcommand.cpp
+++ b/libsqlitepp/sqlite-selectcommand.cpp
@@ -66,7 +66,7 @@ SQLite::SelectCommand::fetch()
case SQLITE_ROW:
if (columns->empty()) {
for (int c = sqlite3_data_count(stmt) - 1; c >= 0; c -= 1) {
- insertColumn(DB::ColumnPtr(new Column(sqlite3_column_name(stmt, c), c, stmt)));
+ insertColumn(std::make_shared<Column>(sqlite3_column_name(stmt, c), c, stmt));
}
}
return true;
diff --git a/libsqlitepp/unittests/Jamfile.jam b/libsqlitepp/unittests/Jamfile.jam
index 91afcae..0eb5b28 100644
--- a/libsqlitepp/unittests/Jamfile.jam
+++ b/libsqlitepp/unittests/Jamfile.jam
@@ -14,6 +14,7 @@ run
<define>BOOST_TEST_DYN_LINK
<library>..//dbpp-sqlite
<library>dbpptestcore
+ <library>..//adhocutil
<library>boost_utf
<library>boost_filesystem
<library>boost_system
diff --git a/libsqlitepp/unittests/testsqlite.cpp b/libsqlitepp/unittests/testsqlite.cpp
index 18707ef..177bdaf 100644
--- a/libsqlitepp/unittests/testsqlite.cpp
+++ b/libsqlitepp/unittests/testsqlite.cpp
@@ -9,9 +9,9 @@
#include <testCore.h>
#include <boost/date_time/posix_time/posix_time.hpp>
-class StandardMockDatabase : public SQLite::Mock {
+class StandardMockDatabase : public DB::PluginMock<SQLite::Mock> {
public:
- StandardMockDatabase() : SQLite::Mock("sqlitemock", {
+ StandardMockDatabase() : DB::PluginMock<SQLite::Mock>("", "sqlitemock", {
rootDir / "sqliteschema.sql" })
{
}
@@ -35,29 +35,25 @@ BOOST_AUTO_TEST_CASE( transactions )
BOOST_REQUIRE_EQUAL(true, ro->inTx());
ro->commitTx();
BOOST_REQUIRE_EQUAL(false, ro->inTx());
-
- delete ro;
}
BOOST_AUTO_TEST_CASE( bindAndSend )
{
auto rw = DB::MockDatabase::openConnectionTo("sqlitemock");
- auto mod = rw->newModifyCommand("INSERT INTO test VALUES(?, ?, ?)");
+ auto mod = rw->modify("INSERT INTO test VALUES(?, ?, ?)");
mod->bindParamI(0, testInt);
mod->bindParamF(1, testDouble);
mod->bindParamS(2, testString);
mod->execute();
BOOST_REQUIRE_EQUAL(2, rw->insertId());
- delete mod;
- delete rw;
}
BOOST_AUTO_TEST_CASE( bindAndSelect )
{
auto ro = DB::MockDatabase::openConnectionTo("sqlitemock");
- auto select = ro->newSelectCommand("SELECT * FROM test WHERE id = ?");
+ auto select = ro->select("SELECT * FROM test WHERE id = ?");
select->bindParamI(0, testInt);
select->execute();
int rows = 0;
@@ -67,9 +63,7 @@ BOOST_AUTO_TEST_CASE( bindAndSelect )
assertColumnValueHelper(*select, 2, testString);
rows += 1;
}
- delete select;
BOOST_REQUIRE_EQUAL(1, rows);
- delete ro;
}
BOOST_AUTO_TEST_SUITE_END();