summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libsqlitepp/sqlite-command.cpp9
-rw-r--r--libsqlitepp/sqlite-connection.cpp14
-rw-r--r--libsqlitepp/sqlite-error.cpp4
-rw-r--r--libsqlitepp/sqlite-error.h2
-rw-r--r--libsqlitepp/sqlite-mock.cpp8
-rw-r--r--libsqlitepp/sqlite-modifycommand.cpp6
-rw-r--r--libsqlitepp/sqlite-modifycommand.h5
-rw-r--r--libsqlitepp/sqlite-selectcommand.cpp2
8 files changed, 21 insertions, 29 deletions
diff --git a/libsqlitepp/sqlite-command.cpp b/libsqlitepp/sqlite-command.cpp
index adaf41e..0ae59d1 100644
--- a/libsqlitepp/sqlite-command.cpp
+++ b/libsqlitepp/sqlite-command.cpp
@@ -1,13 +1,14 @@
#include "sqlite-command.h"
#include "sqlite-connection.h"
-#include <stdlib.h>
-#include <string.h>
+#include <cstdlib>
+#include <cstring>
SQLite::Command::Command(const Connection * conn, const std::string & sql) :
DB::Command(sql),
- c(conn)
+ c(conn),
+ stmt(nullptr)
{
- if (sqlite3_prepare_v2(conn->db, sql.c_str(), sql.length(), &stmt, NULL) != SQLITE_OK) {
+ if (sqlite3_prepare_v2(conn->db, sql.c_str(), sql.length(), &stmt, nullptr) != SQLITE_OK) {
throw Error(conn->db);
}
}
diff --git a/libsqlitepp/sqlite-connection.cpp b/libsqlitepp/sqlite-connection.cpp
index 1539668..a93cad7 100644
--- a/libsqlitepp/sqlite-connection.cpp
+++ b/libsqlitepp/sqlite-connection.cpp
@@ -10,12 +10,12 @@ SQLite::ConnectionError::ConnectionError(sqlite3 * db) :
{
}
-SQLite::Connection::Connection(const std::string & str)
+SQLite::Connection::Connection(const std::string & str) :
+ db(nullptr)
{
if (sqlite3_open(str.c_str(), &db) != SQLITE_OK) {
- ConnectionError err(db);
- sqlite3_close(db);
- throw err;
+ auto dbp = std::unique_ptr<sqlite3, decltype(&sqlite3_close)>(db, &sqlite3_close);
+ throw ConnectionError(dbp.get());
}
}
@@ -27,7 +27,7 @@ SQLite::Connection::~Connection()
void
SQLite::Connection::beginTxInt()
{
- if (sqlite3_exec(db, "BEGIN TRANSACTION", NULL, NULL, NULL) != SQLITE_OK) {
+ if (sqlite3_exec(db, "BEGIN TRANSACTION", nullptr, nullptr, nullptr) != SQLITE_OK) {
throw Error(db);
}
}
@@ -35,7 +35,7 @@ SQLite::Connection::beginTxInt()
void
SQLite::Connection::commitTxInt()
{
- if (sqlite3_exec(db, "COMMIT TRANSACTION", NULL, NULL, NULL) != SQLITE_OK) {
+ if (sqlite3_exec(db, "COMMIT TRANSACTION", nullptr, nullptr, nullptr) != SQLITE_OK) {
throw Error(db);
}
}
@@ -43,7 +43,7 @@ SQLite::Connection::commitTxInt()
void
SQLite::Connection::rollbackTxInt()
{
- if (sqlite3_exec(db, "ROLLBACK TRANSACTION", NULL, NULL, NULL) != SQLITE_OK) {
+ if (sqlite3_exec(db, "ROLLBACK TRANSACTION", nullptr, nullptr, nullptr) != SQLITE_OK) {
throw Error(db);
}
}
diff --git a/libsqlitepp/sqlite-error.cpp b/libsqlitepp/sqlite-error.cpp
index 03ffac4..f1c62e5 100644
--- a/libsqlitepp/sqlite-error.cpp
+++ b/libsqlitepp/sqlite-error.cpp
@@ -1,5 +1,5 @@
#include "sqlite-error.h"
-#include <string.h>
+#include <cstring>
SQLite::Error::Error(sqlite3 * db) :
msg(sqlite3_errmsg(db))
@@ -7,7 +7,7 @@ SQLite::Error::Error(sqlite3 * db) :
}
std::string
-SQLite::Error::message() const throw()
+SQLite::Error::message() const noexcept
{
return msg;
}
diff --git a/libsqlitepp/sqlite-error.h b/libsqlitepp/sqlite-error.h
index a42d2e4..74cff19 100644
--- a/libsqlitepp/sqlite-error.h
+++ b/libsqlitepp/sqlite-error.h
@@ -11,7 +11,7 @@ namespace SQLite {
public:
Error(sqlite3 *);
- std::string message() const throw() override;
+ std::string message() const noexcept override;
private:
std::string msg;
diff --git a/libsqlitepp/sqlite-mock.cpp b/libsqlitepp/sqlite-mock.cpp
index 510b209..4a96e35 100644
--- a/libsqlitepp/sqlite-mock.cpp
+++ b/libsqlitepp/sqlite-mock.cpp
@@ -7,9 +7,9 @@ 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 / boost::lexical_cast<std::string>(getpid()) / boost::lexical_cast<std::string>(++DB::MockDatabase::mocked))
+ testDbPath(std::filesystem::path(root) / name / std::to_string(getpid()) / std::to_string(++DB::MockDatabase::mocked))
{
- CreateNewDatabase();
+ Mock::CreateNewDatabase();
PlaySchemaScripts(ss);
}
@@ -26,7 +26,7 @@ Mock::openConnection() const
Mock::~Mock()
{
- DropDatabase();
+ Mock::DropDatabase();
}
void Mock::DropDatabase() const
@@ -37,7 +37,7 @@ void Mock::DropDatabase() const
void Mock::CreateNewDatabase() const
{
std::filesystem::create_directories(testDbPath.parent_path());
- openConnection(); // Triggers file creation
+ Mock::openConnection(); // Triggers file creation
}
}
diff --git a/libsqlitepp/sqlite-modifycommand.cpp b/libsqlitepp/sqlite-modifycommand.cpp
index d5f44cc..25c771c 100644
--- a/libsqlitepp/sqlite-modifycommand.cpp
+++ b/libsqlitepp/sqlite-modifycommand.cpp
@@ -1,6 +1,6 @@
#include "sqlite-modifycommand.h"
#include "sqlite-error.h"
-#include <stdlib.h>
+#include <cstdlib>
#include "sqlite-connection.h"
SQLite::ModifyCommand::ModifyCommand(const Connection * conn, const std::string & sql) :
@@ -10,10 +10,6 @@ SQLite::ModifyCommand::ModifyCommand(const Connection * conn, const std::string
{
}
-SQLite::ModifyCommand::~ModifyCommand()
-{
-}
-
unsigned int
SQLite::ModifyCommand::execute(bool anc)
{
diff --git a/libsqlitepp/sqlite-modifycommand.h b/libsqlitepp/sqlite-modifycommand.h
index c71dd1f..139e698 100644
--- a/libsqlitepp/sqlite-modifycommand.h
+++ b/libsqlitepp/sqlite-modifycommand.h
@@ -9,13 +9,8 @@ namespace SQLite {
class ModifyCommand : public DB::ModifyCommand, public Command {
public:
ModifyCommand(const Connection *, const std::string & sql);
- virtual ~ModifyCommand();
unsigned int execute(bool) override;
-
- private:
- void prepare() const;
- mutable bool prepared;
};
}
diff --git a/libsqlitepp/sqlite-selectcommand.cpp b/libsqlitepp/sqlite-selectcommand.cpp
index 909dc5c..197356c 100644
--- a/libsqlitepp/sqlite-selectcommand.cpp
+++ b/libsqlitepp/sqlite-selectcommand.cpp
@@ -1,7 +1,7 @@
#include "sqlite-selectcommand.h"
#include "sqlite-connection.h"
#include "sqlite-error.h"
-#include <string.h>
+#include <cstring>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/ordered_index.hpp>