From 7592d966e684410f603942e34413375c8d98ac9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sun, 29 Apr 2018 01:40:46 +0200 Subject: Missing fields in a data-form response are now interpreted as an empty value --- src/database/column.hpp | 16 ++++++++++++++-- src/database/database.hpp | 10 +++++----- src/database/row.hpp | 21 ++++++++++++++++++--- 3 files changed, 37 insertions(+), 10 deletions(-) (limited to 'src/database') diff --git a/src/database/column.hpp b/src/database/column.hpp index 50c9c14..837aa3f 100644 --- a/src/database/column.hpp +++ b/src/database/column.hpp @@ -9,18 +9,30 @@ struct Column value{default_value} {} Column(): value{} {} + void clear() + { + this->value = {}; + } using real_type = T; T value{}; }; +template +struct UnclearableColumn: public Column +{ + using Column::Column; + void clear() + { } +}; + struct ForeignKey: Column { static constexpr auto name = "fk_"; }; -struct Id: Column { +struct Id: UnclearableColumn { static constexpr std::size_t unset_value = static_cast(-1); static constexpr auto name = "id_"; static constexpr auto options = "PRIMARY KEY"; - Id(): Column(unset_value) {} + Id(): UnclearableColumn(unset_value) {} }; diff --git a/src/database/database.hpp b/src/database/database.hpp index d986ecc..30ffcb4 100644 --- a/src/database/database.hpp +++ b/src/database/database.hpp @@ -27,15 +27,15 @@ class Database struct Uuid: Column { static constexpr auto name = "uuid_"; }; - struct Owner: Column { static constexpr auto name = "owner_"; }; + struct Owner: UnclearableColumn { static constexpr auto name = "owner_"; }; - struct IrcChanName: Column { static constexpr auto name = "ircchanname_"; }; + struct IrcChanName: UnclearableColumn { static constexpr auto name = "ircchanname_"; }; - struct Channel: Column { static constexpr auto name = "channel_"; }; + struct Channel: UnclearableColumn { static constexpr auto name = "channel_"; }; - struct IrcServerName: Column { static constexpr auto name = "ircservername_"; }; + struct IrcServerName: UnclearableColumn { static constexpr auto name = "ircservername_"; }; - struct Server: Column { static constexpr auto name = "server_"; }; + struct Server: UnclearableColumn { static constexpr auto name = "server_"; }; struct Date: Column { static constexpr auto name = "date_"; }; diff --git a/src/database/row.hpp b/src/database/row.hpp index 27caf43..1253f93 100644 --- a/src/database/row.hpp +++ b/src/database/row.hpp @@ -1,7 +1,5 @@ #pragma once -#include - #include template @@ -25,7 +23,24 @@ struct Row return col.value; } -public: + void clear() + { + this->clear_col<0>(); + } + std::tuple columns; std::string table_name; + +private: + template + typename std::enable_if::type + clear_col() + { + std::get(this->columns).clear(); + this->clear_col(); + } + template + typename std::enable_if::type + clear_col() + { } }; -- cgit v1.2.3