summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2020-11-18 16:55:31 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2020-11-18 16:55:31 +0000
commit0af57e2595922c9ee59d7cd489daf37a3550496c (patch)
tree73f8069e421e64222380fb3d30b2fb1277f80cd3
parentFixes for tidy (diff)
downloadlibdbpp-sqlite-0af57e2595922c9ee59d7cd489daf37a3550496c.tar.bz2
libdbpp-sqlite-0af57e2595922c9ee59d7cd489daf37a3550496c.tar.xz
libdbpp-sqlite-0af57e2595922c9ee59d7cd489daf37a3550496c.zip
Clang format
-rw-r--r--libsqlitepp/sqlite-command.cpp6
-rw-r--r--libsqlitepp/sqlite-command.h42
-rw-r--r--libsqlitepp/sqlite-connection.cpp12
-rw-r--r--libsqlitepp/sqlite-connection.h33
-rw-r--r--libsqlitepp/sqlite-error.cpp6
-rw-r--r--libsqlitepp/sqlite-error.h11
-rw-r--r--libsqlitepp/sqlite-mock.cpp70
-rw-r--r--libsqlitepp/sqlite-mock.h10
-rw-r--r--libsqlitepp/sqlite-modifycommand.cpp7
-rw-r--r--libsqlitepp/sqlite-modifycommand.h11
-rw-r--r--libsqlitepp/sqlite-selectcommand.cpp70
-rw-r--r--libsqlitepp/sqlite-selectcommand.h12
-rw-r--r--libsqlitepp/unittests/testsqlite.cpp22
13 files changed, 139 insertions, 173 deletions
diff --git a/libsqlitepp/sqlite-command.cpp b/libsqlitepp/sqlite-command.cpp
index 0020679..124b5d0 100644
--- a/libsqlitepp/sqlite-command.cpp
+++ b/libsqlitepp/sqlite-command.cpp
@@ -3,10 +3,7 @@
#include <cstdlib>
#include <cstring>
-SQLite::Command::Command(const Connection * conn, const std::string & sql) :
- DB::Command(sql),
- c(conn),
- stmt(nullptr)
+SQLite::Command::Command(const Connection * conn, const std::string & sql) : DB::Command(sql), c(conn), stmt(nullptr)
{
if (sqlite3_prepare_v2(conn->db, sql.c_str(), sql.length(), &stmt, nullptr) != SQLITE_OK) {
throw Error(conn->db);
@@ -108,4 +105,3 @@ SQLite::Command::bindNull(unsigned int n)
throw Error(c->db);
}
}
-
diff --git a/libsqlitepp/sqlite-command.h b/libsqlitepp/sqlite-command.h
index cbc9932..1fe9b6a 100644
--- a/libsqlitepp/sqlite-command.h
+++ b/libsqlitepp/sqlite-command.h
@@ -7,36 +7,34 @@
namespace SQLite {
class Connection;
class Command : public virtual DB::Command {
- public:
- Command(const Connection *, const std::string & sql);
- virtual ~Command() = 0;
+ public:
+ Command(const Connection *, const std::string & sql);
+ virtual ~Command() = 0;
- void bindParamI(unsigned int, int) override;
- void bindParamI(unsigned int, long int) override;
- void bindParamI(unsigned int, long long int) override;
- void bindParamI(unsigned int, unsigned int) override;
- void bindParamI(unsigned int, long unsigned int) override;
- void bindParamI(unsigned int, long long unsigned int) override;
+ void bindParamI(unsigned int, int) override;
+ void bindParamI(unsigned int, long int) override;
+ void bindParamI(unsigned int, long long int) override;
+ void bindParamI(unsigned int, unsigned int) override;
+ void bindParamI(unsigned int, long unsigned int) override;
+ void bindParamI(unsigned int, long long unsigned int) override;
- void bindParamB(unsigned int, bool) override;
+ void bindParamB(unsigned int, bool) override;
- void bindParamF(unsigned int, double) override;
- void bindParamF(unsigned int, float) override;
+ void bindParamF(unsigned int, double) override;
+ void bindParamF(unsigned int, float) override;
- void bindParamS(unsigned int, const Glib::ustring&) override;
- void bindParamS(unsigned int, const std::string_view&) override;
+ void bindParamS(unsigned int, const Glib::ustring &) override;
+ void bindParamS(unsigned int, const std::string_view &) override;
- void bindParamT(unsigned int, const boost::posix_time::time_duration &) override;
- void bindParamT(unsigned int, const boost::posix_time::ptime &) override;
+ void bindParamT(unsigned int, const boost::posix_time::time_duration &) override;
+ void bindParamT(unsigned int, const boost::posix_time::ptime &) override;
- void bindNull(unsigned int) override;
+ void bindNull(unsigned int) override;
- protected:
- const Connection * c;
- sqlite3_stmt * stmt;
+ protected:
+ const Connection * c;
+ sqlite3_stmt * stmt;
};
}
#endif
-
-
diff --git a/libsqlitepp/sqlite-connection.cpp b/libsqlitepp/sqlite-connection.cpp
index a93cad7..99006dc 100644
--- a/libsqlitepp/sqlite-connection.cpp
+++ b/libsqlitepp/sqlite-connection.cpp
@@ -1,17 +1,13 @@
#include "sqlite-connection.h"
#include "sqlite-error.h"
-#include "sqlite-selectcommand.h"
#include "sqlite-modifycommand.h"
+#include "sqlite-selectcommand.h"
NAMEDFACTORY("sqlite", SQLite::Connection, DB::ConnectionFactory);
-SQLite::ConnectionError::ConnectionError(sqlite3 * db) :
- SQLite::Error(db)
-{
-}
+SQLite::ConnectionError::ConnectionError(sqlite3 * db) : SQLite::Error(db) { }
-SQLite::Connection::Connection(const std::string & str) :
- db(nullptr)
+SQLite::Connection::Connection(const std::string & str) : db(nullptr)
{
if (sqlite3_open(str.c_str(), &db) != SQLITE_OK) {
auto dbp = std::unique_ptr<sqlite3, decltype(&sqlite3_close)>(db, &sqlite3_close);
@@ -66,7 +62,6 @@ SQLite::Connection::ping() const
// Can this fail?
}
-
DB::SelectCommandPtr
SQLite::Connection::select(const std::string & sql, const DB::CommandOptionsCPtr &)
{
@@ -84,4 +79,3 @@ SQLite::Connection::insertId()
{
return sqlite3_last_insert_rowid(db);
}
-
diff --git a/libsqlitepp/sqlite-connection.h b/libsqlitepp/sqlite-connection.h
index ba8410d..0d77911 100644
--- a/libsqlitepp/sqlite-connection.h
+++ b/libsqlitepp/sqlite-connection.h
@@ -1,36 +1,35 @@
#ifndef SQLITE_CONNECTION_H
#define SQLITE_CONNECTION_H
-#include <connection.h>
#include "sqlite-error.h"
+#include <connection.h>
#include <sqlite3.h>
namespace SQLite {
class ConnectionError : public virtual Error, public virtual DB::ConnectionError {
- public:
- ConnectionError(sqlite3 *);
+ public:
+ ConnectionError(sqlite3 *);
};
class Connection : public DB::Connection {
- public:
- Connection(const std::string & info);
- ~Connection();
+ public:
+ Connection(const std::string & info);
+ ~Connection();
- void beginTxInt() override;
- void commitTxInt() override;
- void rollbackTxInt() override;
- void ping() const override;
- DB::BulkDeleteStyle bulkDeleteStyle() const override;
- DB::BulkUpdateStyle bulkUpdateStyle() const override;
+ void beginTxInt() override;
+ void commitTxInt() override;
+ void rollbackTxInt() override;
+ void ping() const override;
+ DB::BulkDeleteStyle bulkDeleteStyle() const override;
+ DB::BulkUpdateStyle bulkUpdateStyle() const override;
- DB::SelectCommandPtr select(const std::string & sql, const DB::CommandOptionsCPtr &) override;
- DB::ModifyCommandPtr modify(const std::string & sql, const DB::CommandOptionsCPtr &) 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;
+ int64_t insertId() override;
- sqlite3 * db;
+ sqlite3 * db;
};
}
#endif
-
diff --git a/libsqlitepp/sqlite-error.cpp b/libsqlitepp/sqlite-error.cpp
index f1c62e5..0e4d084 100644
--- a/libsqlitepp/sqlite-error.cpp
+++ b/libsqlitepp/sqlite-error.cpp
@@ -1,14 +1,10 @@
#include "sqlite-error.h"
#include <cstring>
-SQLite::Error::Error(sqlite3 * db) :
- msg(sqlite3_errmsg(db))
-{
-}
+SQLite::Error::Error(sqlite3 * db) : msg(sqlite3_errmsg(db)) { }
std::string
SQLite::Error::message() const noexcept
{
return msg;
}
-
diff --git a/libsqlitepp/sqlite-error.h b/libsqlitepp/sqlite-error.h
index 74cff19..337cd1b 100644
--- a/libsqlitepp/sqlite-error.h
+++ b/libsqlitepp/sqlite-error.h
@@ -8,15 +8,14 @@
namespace SQLite {
class Error : public AdHoc::Exception<DB::Error> {
- public:
- Error(sqlite3 *);
+ public:
+ Error(sqlite3 *);
- std::string message() const noexcept override;
+ std::string message() const noexcept override;
- private:
- std::string msg;
+ private:
+ std::string msg;
};
}
#endif
-
diff --git a/libsqlitepp/sqlite-mock.cpp b/libsqlitepp/sqlite-mock.cpp
index 18f7df8..4772bcc 100644
--- a/libsqlitepp/sqlite-mock.cpp
+++ b/libsqlitepp/sqlite-mock.cpp
@@ -6,39 +6,41 @@ NAMEDFACTORY("sqlite", SQLite::Mock, DB::MockDatabaseFactory);
namespace SQLite {
-Mock::Mock(const std::string & root, const std::string & name, const std::vector<std::filesystem::path> & ss) :
- testDbPath(std::filesystem::path(root) / name / std::to_string(getpid()) / std::to_string(++DB::MockDatabase::mocked))
-{
- Mock::CreateNewDatabase();
- PlaySchemaScripts(ss);
-}
-
-Mock::Mock(const std::string & name, const std::vector<std::filesystem::path> & ss) :
- Mock("/tmp/sqliteut", name, ss)
-{
-}
-
-DB::ConnectionPtr
-Mock::openConnection() const
-{
- return std::make_shared<Connection>(testDbPath.string());
-}
-
-Mock::~Mock()
-{
- Mock::DropDatabase();
-}
-
-void Mock::DropDatabase() const
-{
- std::filesystem::remove(testDbPath);
-}
+ Mock::Mock(const std::string & root, const std::string & name, const std::vector<std::filesystem::path> & ss) :
+ testDbPath(std::filesystem::path(root) / name / std::to_string(getpid())
+ / std::to_string(++DB::MockDatabase::mocked))
+ {
+ Mock::CreateNewDatabase();
+ PlaySchemaScripts(ss);
+ }
+
+ Mock::Mock(const std::string & name, const std::vector<std::filesystem::path> & ss) :
+ Mock("/tmp/sqliteut", name, ss)
+ {
+ }
+
+ DB::ConnectionPtr
+ Mock::openConnection() const
+ {
+ return std::make_shared<Connection>(testDbPath.string());
+ }
+
+ Mock::~Mock()
+ {
+ Mock::DropDatabase();
+ }
+
+ void
+ Mock::DropDatabase() const
+ {
+ std::filesystem::remove(testDbPath);
+ }
+
+ void
+ Mock::CreateNewDatabase() const
+ {
+ std::filesystem::create_directories(testDbPath.parent_path());
+ (void)Mock::openConnection(); // Triggers file creation
+ }
-void Mock::CreateNewDatabase() const
-{
- std::filesystem::create_directories(testDbPath.parent_path());
- (void) Mock::openConnection(); // Triggers file creation
}
-
-}
-
diff --git a/libsqlitepp/sqlite-mock.h b/libsqlitepp/sqlite-mock.h
index 45caef9..fd8a8e9 100644
--- a/libsqlitepp/sqlite-mock.h
+++ b/libsqlitepp/sqlite-mock.h
@@ -1,14 +1,14 @@
#ifndef MOCKSQLITEDATASOURCE_H
#define MOCKSQLITEDATASOURCE_H
-#include <mockDatabase.h>
+#include <c++11Helpers.h>
#include <filesystem>
+#include <mockDatabase.h>
#include <visibility.h>
-#include <c++11Helpers.h>
namespace SQLite {
-class DLL_PUBLIC Mock : public DB::MockDatabase {
+ class DLL_PUBLIC Mock : public DB::MockDatabase {
public:
Mock(const std::string & root, const std::string & name, const std::vector<std::filesystem::path> & ss);
Mock(const std::string & name, const std::vector<std::filesystem::path> & ss);
@@ -24,10 +24,8 @@ class DLL_PUBLIC Mock : public DB::MockDatabase {
private:
const std::filesystem::path testDbPath;
-};
+ };
}
#endif
-
-
diff --git a/libsqlitepp/sqlite-modifycommand.cpp b/libsqlitepp/sqlite-modifycommand.cpp
index 25c771c..868f187 100644
--- a/libsqlitepp/sqlite-modifycommand.cpp
+++ b/libsqlitepp/sqlite-modifycommand.cpp
@@ -1,12 +1,10 @@
#include "sqlite-modifycommand.h"
+#include "sqlite-connection.h"
#include "sqlite-error.h"
#include <cstdlib>
-#include "sqlite-connection.h"
SQLite::ModifyCommand::ModifyCommand(const Connection * conn, const std::string & sql) :
- DB::Command(sql),
- DB::ModifyCommand(sql),
- SQLite::Command(conn, sql)
+ DB::Command(sql), DB::ModifyCommand(sql), SQLite::Command(conn, sql)
{
}
@@ -24,4 +22,3 @@ SQLite::ModifyCommand::execute(bool anc)
}
return rows;
}
-
diff --git a/libsqlitepp/sqlite-modifycommand.h b/libsqlitepp/sqlite-modifycommand.h
index 139e698..d9f58c6 100644
--- a/libsqlitepp/sqlite-modifycommand.h
+++ b/libsqlitepp/sqlite-modifycommand.h
@@ -1,20 +1,17 @@
#ifndef SQLITE_MODIFYCOMMAND_H
#define SQLITE_MODIFYCOMMAND_H
-#include <modifycommand.h>
#include "sqlite-command.h"
+#include <modifycommand.h>
namespace SQLite {
class Connection;
class ModifyCommand : public DB::ModifyCommand, public Command {
- public:
- ModifyCommand(const Connection *, const std::string & sql);
+ public:
+ ModifyCommand(const Connection *, const std::string & sql);
- unsigned int execute(bool) override;
+ unsigned int execute(bool) override;
};
}
#endif
-
-
-
diff --git a/libsqlitepp/sqlite-selectcommand.cpp b/libsqlitepp/sqlite-selectcommand.cpp
index 7ad8486..c4a1096 100644
--- a/libsqlitepp/sqlite-selectcommand.cpp
+++ b/libsqlitepp/sqlite-selectcommand.cpp
@@ -1,55 +1,52 @@
#include "sqlite-selectcommand.h"
#include "sqlite-connection.h"
#include "sqlite-error.h"
-#include <cstring>
-#include <boost/multi_index_container.hpp>
#include <boost/multi_index/ordered_index.hpp>
+#include <boost/multi_index_container.hpp>
+#include <cstring>
namespace SQLite {
class Column : public DB::Column {
- public:
- Column(const Glib::ustring & n, unsigned int i, sqlite3_stmt * s) :
- DB::Column(n, i),
- stmt(s)
- {
- }
+ public:
+ Column(const Glib::ustring & n, unsigned int i, sqlite3_stmt * s) : DB::Column(n, i), stmt(s) { }
- [[nodiscard]] bool isNull() const override {
- return (SQLITE_NULL == sqlite3_column_type(stmt, (int)colNo));
- }
+ [[nodiscard]] bool
+ isNull() const override
+ {
+ return (SQLITE_NULL == sqlite3_column_type(stmt, (int)colNo));
+ }
- void apply(DB::HandleField & h) const override {
- switch (sqlite3_column_type(stmt, (int)colNo)) {
- case SQLITE_INTEGER:
- h.integer(sqlite3_column_int64(stmt, (int)colNo));
- return;
- case SQLITE_FLOAT:
- h.floatingpoint(sqlite3_column_double(stmt, (int)colNo));
- return;
- case SQLITE_TEXT:
- {
- auto t = sqlite3_column_text(stmt, (int)colNo);
- auto l = sqlite3_column_bytes(stmt, (int)colNo);
- h.string({ reinterpret_cast<const char *>(t), (std::size_t)l });
- return;
- }
- case SQLITE_NULL:
- h.null();
- return;
- case SQLITE_BLOB:
- throw DB::ColumnTypeNotSupported();
+ void
+ apply(DB::HandleField & h) const override
+ {
+ switch (sqlite3_column_type(stmt, (int)colNo)) {
+ case SQLITE_INTEGER:
+ h.integer(sqlite3_column_int64(stmt, (int)colNo));
+ return;
+ case SQLITE_FLOAT:
+ h.floatingpoint(sqlite3_column_double(stmt, (int)colNo));
+ return;
+ case SQLITE_TEXT: {
+ auto t = sqlite3_column_text(stmt, (int)colNo);
+ auto l = sqlite3_column_bytes(stmt, (int)colNo);
+ h.string({reinterpret_cast<const char *>(t), (std::size_t)l});
+ return;
}
+ case SQLITE_NULL:
+ h.null();
+ return;
+ case SQLITE_BLOB:
+ throw DB::ColumnTypeNotSupported();
}
+ }
- private:
- sqlite3_stmt * const stmt;
+ private:
+ sqlite3_stmt * const stmt;
};
}
SQLite::SelectCommand::SelectCommand(const Connection * conn, const std::string & sql) :
- DB::Command(sql),
- DB::SelectCommand(sql),
- SQLite::Command(conn, sql)
+ DB::Command(sql), DB::SelectCommand(sql), SQLite::Command(conn, sql)
{
}
@@ -76,4 +73,3 @@ SQLite::SelectCommand::fetch()
throw Error(c->db);
}
}
-
diff --git a/libsqlitepp/sqlite-selectcommand.h b/libsqlitepp/sqlite-selectcommand.h
index 8c9b04d..30e0118 100644
--- a/libsqlitepp/sqlite-selectcommand.h
+++ b/libsqlitepp/sqlite-selectcommand.h
@@ -1,21 +1,19 @@
#ifndef SQLITE_SELECTCOMMAND_H
#define SQLITE_SELECTCOMMAND_H
-#include <selectcommand.h>
#include "sqlite-command.h"
+#include <selectcommand.h>
namespace SQLite {
class Connection;
class ColumnBase;
class SelectCommand : public DB::SelectCommand, public Command {
- public:
- SelectCommand(const Connection *, const std::string & sql);
+ public:
+ SelectCommand(const Connection *, const std::string & sql);
- bool fetch() override;
- void execute() override;
+ bool fetch() override;
+ void execute() override;
};
}
#endif
-
-
diff --git a/libsqlitepp/unittests/testsqlite.cpp b/libsqlitepp/unittests/testsqlite.cpp
index f742acd..81127c8 100644
--- a/libsqlitepp/unittests/testsqlite.cpp
+++ b/libsqlitepp/unittests/testsqlite.cpp
@@ -1,27 +1,24 @@
#define BOOST_TEST_MODULE TestSQLite
#include <boost/test/unit_test.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <column.h>
#include <definedDirs.h>
#include <modifycommand.h>
#include <selectcommand.h>
-#include <column.h>
#include <sqlite-mock.h>
#include <testCore.h>
-#include <boost/date_time/posix_time/posix_time.hpp>
class StandardMockDatabase : public DB::PluginMock<SQLite::Mock> {
- public:
- StandardMockDatabase() : DB::PluginMock<SQLite::Mock>("sqlitemock", {
- rootDir / "sqliteschema.sql" })
- {
- }
+public:
+ StandardMockDatabase() : DB::PluginMock<SQLite::Mock>("sqlitemock", {rootDir / "sqliteschema.sql"}) { }
};
-BOOST_GLOBAL_FIXTURE( StandardMockDatabase );
+BOOST_GLOBAL_FIXTURE(StandardMockDatabase);
-BOOST_FIXTURE_TEST_SUITE( Core, DB::TestCore );
+BOOST_FIXTURE_TEST_SUITE(Core, DB::TestCore);
-BOOST_AUTO_TEST_CASE( transactions )
+BOOST_AUTO_TEST_CASE(transactions)
{
auto ro = DB::MockDatabase::openConnectionTo("sqlitemock");
@@ -37,7 +34,7 @@ BOOST_AUTO_TEST_CASE( transactions )
BOOST_REQUIRE_EQUAL(false, ro->inTx());
}
-BOOST_AUTO_TEST_CASE( bindAndSend )
+BOOST_AUTO_TEST_CASE(bindAndSend)
{
auto rw = DB::MockDatabase::openConnectionTo("sqlitemock");
@@ -49,7 +46,7 @@ BOOST_AUTO_TEST_CASE( bindAndSend )
BOOST_REQUIRE_EQUAL(2, rw->insertId());
}
-BOOST_AUTO_TEST_CASE( bindAndSelect )
+BOOST_AUTO_TEST_CASE(bindAndSelect)
{
auto ro = DB::MockDatabase::openConnectionTo("sqlitemock");
@@ -67,4 +64,3 @@ BOOST_AUTO_TEST_CASE( bindAndSelect )
}
BOOST_AUTO_TEST_SUITE_END();
-