diff options
Diffstat (limited to 'src/database')
-rw-r--r-- | src/database/count_query.hpp | 4 | ||||
-rw-r--r-- | src/database/database.cpp | 5 | ||||
-rw-r--r-- | src/database/database.hpp | 9 | ||||
-rw-r--r-- | src/database/postgresql_statement.hpp | 10 | ||||
-rw-r--r-- | src/database/query.cpp | 5 | ||||
-rw-r--r-- | src/database/query.hpp | 9 | ||||
-rw-r--r-- | src/database/row.hpp | 2 | ||||
-rw-r--r-- | src/database/select_query.hpp | 2 |
8 files changed, 17 insertions, 29 deletions
diff --git a/src/database/count_query.hpp b/src/database/count_query.hpp index 118ce44..3990eb9 100644 --- a/src/database/count_query.hpp +++ b/src/database/count_query.hpp @@ -8,10 +8,10 @@ struct CountQuery: public Query { - CountQuery(std::string name): + CountQuery(const std::string& name): Query("SELECT count(*) FROM ") { - this->body += std::move(name); + this->body += name; } int64_t execute(DatabaseEngine& db) diff --git a/src/database/database.cpp b/src/database/database.cpp index 6e08ee1..861abcb 100644 --- a/src/database/database.cpp +++ b/src/database/database.cpp @@ -162,10 +162,6 @@ Database::IrcChannelOptions Database::get_irc_channel_options_with_server_and_gl coptions.col<EncodingOut>() = get_first_non_empty(coptions.col<EncodingOut>(), soptions.col<EncodingOut>()); - coptions.col<MaxHistoryLength>() = get_first_non_empty(coptions.col<MaxHistoryLength>(), - soptions.col<MaxHistoryLength>(), - goptions.col<MaxHistoryLength>()); - return coptions; } @@ -338,7 +334,6 @@ Transaction::Transaction() log_error("Failed to create SQL transaction: ", std::get<std::string>(result)); else this->success = true; - } Transaction::~Transaction() diff --git a/src/database/database.hpp b/src/database/database.hpp index 3e25b30..a53f87b 100644 --- a/src/database/database.hpp +++ b/src/database/database.hpp @@ -63,8 +63,8 @@ class Database struct EncodingIn: Column<std::string> { static constexpr auto name = "encodingin_"; }; - struct MaxHistoryLength: Column<int> { static constexpr auto name = "maxhistorylength_"; - MaxHistoryLength(): Column<int>(20) {} }; + struct MaxHistoryLength: Column<std::int64_t> { static constexpr auto name = "maxhistorylength_"; + MaxHistoryLength(): Column<std::int64_t>(20) {} }; struct RecordHistory: Column<bool> { static constexpr auto name = "recordhistory_"; RecordHistory(): Column<bool>(true) {}}; @@ -86,13 +86,16 @@ class Database struct Address: Column<std::string> { static constexpr auto name = "address_"; }; + struct ThrottleLimit: Column<std::int64_t> { static constexpr auto name = "throttlelimit_"; + ThrottleLimit(): Column<std::int64_t>(10) {} }; + using MucLogLineTable = Table<Id, Uuid, Owner, IrcChanName, IrcServerName, Date, Body, Nick>; using MucLogLine = MucLogLineTable::RowType; using GlobalOptionsTable = Table<Id, Owner, MaxHistoryLength, RecordHistory, GlobalPersistent>; using GlobalOptions = GlobalOptionsTable::RowType; - using IrcServerOptionsTable = Table<Id, Owner, Server, Pass, TlsPorts, Ports, Username, Realname, VerifyCert, TrustedFingerprint, EncodingOut, EncodingIn, MaxHistoryLength, Address, Nick>; + using IrcServerOptionsTable = Table<Id, Owner, Server, Pass, TlsPorts, Ports, Username, Realname, VerifyCert, TrustedFingerprint, EncodingOut, EncodingIn, MaxHistoryLength, Address, Nick, ThrottleLimit>; using IrcServerOptions = IrcServerOptionsTable::RowType; using IrcChannelOptionsTable = Table<Id, Owner, Server, Channel, EncodingOut, EncodingIn, MaxHistoryLength, Persistent, RecordHistoryOptional>; diff --git a/src/database/postgresql_statement.hpp b/src/database/postgresql_statement.hpp index 37e8ea0..345a942 100644 --- a/src/database/postgresql_statement.hpp +++ b/src/database/postgresql_statement.hpp @@ -15,7 +15,7 @@ class PostgresqlStatement: public Statement body(std::move(body)), conn(conn) {} - ~PostgresqlStatement() + virtual ~PostgresqlStatement() { PQclear(this->result); this->result = nullptr; @@ -89,8 +89,6 @@ class PostgresqlStatement: public Statement return true; } - private: - private: bool execute(const bool second_attempt=false) { @@ -119,11 +117,7 @@ private: PQreset(this->conn); return this->execute(true); } - else - { - log_error("Givin up."); - return false; - } + return false; } return true; } diff --git a/src/database/query.cpp b/src/database/query.cpp index d72066e..5ec8599 100644 --- a/src/database/query.cpp +++ b/src/database/query.cpp @@ -6,11 +6,6 @@ void actual_bind(Statement& statement, const std::string& value, int index) statement.bind_text(index, value); } -void actual_bind(Statement& statement, const std::int64_t& value, int index) -{ - statement.bind_int64(index, value); -} - void actual_bind(Statement& statement, const OptionalBool& value, int index) { if (!value.is_set) diff --git a/src/database/query.hpp b/src/database/query.hpp index ba28b1a..c89371f 100644 --- a/src/database/query.hpp +++ b/src/database/query.hpp @@ -12,13 +12,14 @@ #include <string> void actual_bind(Statement& statement, const std::string& value, int index); -void actual_bind(Statement& statement, const std::int64_t& value, int index); -template <typename T, typename std::enable_if_t<std::is_integral<T>::value>* = 0> +void actual_bind(Statement& statement, const OptionalBool& value, int index); +template <typename T> void actual_bind(Statement& statement, const T& value, int index) { - actual_bind(statement, static_cast<std::int64_t>(value), index); + static_assert(std::is_integral<T>::value, + "Only a string, an optional-bool or an integer can be used."); + statement.bind_int64(index, static_cast<std::int64_t>(value)); } -void actual_bind(Statement& statement, const OptionalBool& value, int index); #ifdef DEBUG_SQL_QUERIES #include <utils/scopetimer.hpp> diff --git a/src/database/row.hpp b/src/database/row.hpp index 1253f93..4004b5d 100644 --- a/src/database/row.hpp +++ b/src/database/row.hpp @@ -28,7 +28,7 @@ struct Row this->clear_col<0>(); } - std::tuple<T...> columns; + std::tuple<T...> columns{}; std::string table_name; private: diff --git a/src/database/select_query.hpp b/src/database/select_query.hpp index b9fdc06..e372f2e 100644 --- a/src/database/select_query.hpp +++ b/src/database/select_query.hpp @@ -135,7 +135,7 @@ struct SelectQuery: public Query }; template <typename... T> -auto select(const Table<T...> table) +auto select(const Table<T...>& table) { SelectQuery<T...> query(table.name); return query; |