From 369ccb037619871403b14c959bbb359332133810 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 13 Jun 2017 11:18:05 +0200 Subject: Add default values for the database columns --- src/bridge/bridge.cpp | 6 ++++-- src/database/column.hpp | 6 +++++- src/database/database.hpp | 18 ++++++++++++------ 3 files changed, 21 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index fcfcc24..23ecfe9 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -23,12 +23,14 @@ static std::string in_encoding_for(const Bridge& bridge, const Iid& iid) #ifdef USE_DATABASE const auto jid = bridge.get_bare_jid(); auto options = Database::get_irc_channel_options_with_server_default(jid, iid.get_server(), iid.get_local()); - return options.col(); + auto result = options.col(); + if (!result.empty()) + return result; #else (void)bridge; (void)iid; - return {"ISO-8859-1"}; #endif + return {"ISO-8859-1"}; } Bridge::Bridge(std::string user_jid, BiboumiComponent& xmpp, std::shared_ptr& poller): diff --git a/src/database/column.hpp b/src/database/column.hpp index e74d426..22f4254 100644 --- a/src/database/column.hpp +++ b/src/database/column.hpp @@ -5,8 +5,12 @@ template struct Column { + Column(T default_value): + value{default_value} {} + Column(): + value{} {} using real_type = T; - T value; + T value{}; }; struct Id: Column { static constexpr auto name = "id_"; diff --git a/src/database/database.hpp b/src/database/database.hpp index ebc4878..a0611c1 100644 --- a/src/database/database.hpp +++ b/src/database/database.hpp @@ -49,10 +49,12 @@ class Database static constexpr auto options = ""; }; struct Ports: Column { static constexpr auto name = "tlsPorts_"; - static constexpr auto options = ""; }; + static constexpr auto options = ""; + Ports(): Column("6667") {}}; struct TlsPorts: Column { static constexpr auto name = "ports_"; - static constexpr auto options = ""; }; + static constexpr auto options = ""; + TlsPorts(): Column("6697;6670") {} }; struct Username: Column { static constexpr auto name = "username_"; static constexpr auto options = ""; }; @@ -73,16 +75,20 @@ class Database static constexpr auto options = ""; }; struct MaxHistoryLength: Column { static constexpr auto name = "maxHistoryLength_"; - static constexpr auto options = ""; }; + static constexpr auto options = ""; + MaxHistoryLength(): Column(20) {} }; struct RecordHistory: Column { static constexpr auto name = "recordHistory_"; - static constexpr auto options = ""; }; + static constexpr auto options = ""; + RecordHistory(): Column(true) {}}; struct VerifyCert: Column { static constexpr auto name = "verifyCert_"; - static constexpr auto options = ""; }; + static constexpr auto options = ""; + VerifyCert(): Column(true) {} }; struct Persistent: Column { static constexpr auto name = "persistent_"; - static constexpr auto options = ""; }; + static constexpr auto options = ""; + Persistent(): Column(false) {} }; using MucLogLineTable = Table; using MucLogLine = MucLogLineTable::RowType; -- cgit v1.2.3