From 9e4a3e2b054ee4604b6a42c73895216c68fa96e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Mon, 12 Mar 2018 00:17:03 +0100 Subject: =?UTF-8?q?Fix=20the=20INSERT=20query=20for=20types=20that=20don?= =?UTF-8?q?=E2=80=99t=20have=20any=20Id=20column?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/database/row.hpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/database/row.hpp') diff --git a/src/database/row.hpp b/src/database/row.hpp index 4dc98be..3703ff7 100644 --- a/src/database/row.hpp +++ b/src/database/row.hpp @@ -50,7 +50,8 @@ struct Row } private: - void insert(DatabaseEngine& db) + template + void insert(DatabaseEngine& db, typename std::enable_if && Coucou>::type* = nullptr) { InsertQuery query(this->table_name, this->columns); // Ugly workaround for non portable stuff @@ -58,6 +59,13 @@ struct Row query.execute(db, this->columns); } + template + void insert(DatabaseEngine& db, typename std::enable_if && Coucou>::type* = nullptr) + { + InsertQuery query(this->table_name, this->columns); + query.execute(db, this->columns); + } + void update(DatabaseEngine& db) { UpdateQuery query(this->table_name, this->columns); -- cgit v1.2.3 From d62ca9f87906be6f046fe9d07afb8bfb69c166e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Fri, 16 Mar 2018 01:11:47 +0100 Subject: Use if constexpr to make things a lot more readable --- src/database/row.hpp | 52 +++++++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 27 deletions(-) (limited to 'src/database/row.hpp') diff --git a/src/database/row.hpp b/src/database/row.hpp index 3703ff7..194a9c5 100644 --- a/src/database/row.hpp +++ b/src/database/row.hpp @@ -29,41 +29,39 @@ struct Row return col.value; } - template - void save(std::unique_ptr& db, typename std::enable_if && Coucou>::type* = nullptr) + void save(std::unique_ptr& db) { - this->insert(*db); - } - - template - void save(std::unique_ptr& db, typename std::enable_if && Coucou>::type* = nullptr) - { - const Id& id = std::get(this->columns); - if (id.value == Id::unset_value) + if constexpr(is_one_of) { - this->insert(*db); - if (db->last_inserted_rowid >= 0) - std::get(this->columns).value = static_cast(db->last_inserted_rowid); + const Id& id = std::get(this->columns); + if (id.value == Id::unset_value) + { + this->insert(*db); + if (db->last_inserted_rowid >= 0) + std::get(this->columns).value = static_cast(db->last_inserted_rowid); + } + else + this->update(*db); } else - this->update(*db); + this->insert(*db); } private: - template - void insert(DatabaseEngine& db, typename std::enable_if && Coucou>::type* = nullptr) - { - InsertQuery query(this->table_name, this->columns); - // Ugly workaround for non portable stuff - query.body += db.get_returning_id_sql_string(Id::name); - query.execute(db, this->columns); - } - - template - void insert(DatabaseEngine& db, typename std::enable_if && Coucou>::type* = nullptr) + void insert(DatabaseEngine& db) { - InsertQuery query(this->table_name, this->columns); - query.execute(db, this->columns); + if constexpr(is_one_of) + { + InsertQuery query(this->table_name, this->columns); + // Ugly workaround for non portable stuff + query.body += db.get_returning_id_sql_string(Id::name); + query.execute(db, this->columns); + } + else + { + InsertQuery query(this->table_name, this->columns); + query.execute(db, this->columns); + } } void update(DatabaseEngine& db) -- cgit v1.2.3 From d0e3c71b91f1a1c1780158789fd42b8ac7209495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sat, 17 Mar 2018 17:28:41 +0100 Subject: Revert "Use if constexpr to make things a lot more readable" This reverts commit d62ca9f87906be6f046fe9d07afb8bfb69c166e3. --- src/database/row.hpp | 52 +++++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 25 deletions(-) (limited to 'src/database/row.hpp') diff --git a/src/database/row.hpp b/src/database/row.hpp index 194a9c5..3703ff7 100644 --- a/src/database/row.hpp +++ b/src/database/row.hpp @@ -29,39 +29,41 @@ struct Row return col.value; } - void save(std::unique_ptr& db) + template + void save(std::unique_ptr& db, typename std::enable_if && Coucou>::type* = nullptr) { - if constexpr(is_one_of) + this->insert(*db); + } + + template + void save(std::unique_ptr& db, typename std::enable_if && Coucou>::type* = nullptr) + { + const Id& id = std::get(this->columns); + if (id.value == Id::unset_value) { - const Id& id = std::get(this->columns); - if (id.value == Id::unset_value) - { - this->insert(*db); - if (db->last_inserted_rowid >= 0) - std::get(this->columns).value = static_cast(db->last_inserted_rowid); - } - else - this->update(*db); + this->insert(*db); + if (db->last_inserted_rowid >= 0) + std::get(this->columns).value = static_cast(db->last_inserted_rowid); } else - this->insert(*db); + this->update(*db); } private: - void insert(DatabaseEngine& db) + template + void insert(DatabaseEngine& db, typename std::enable_if && Coucou>::type* = nullptr) { - if constexpr(is_one_of) - { - InsertQuery query(this->table_name, this->columns); - // Ugly workaround for non portable stuff - query.body += db.get_returning_id_sql_string(Id::name); - query.execute(db, this->columns); - } - else - { - InsertQuery query(this->table_name, this->columns); - query.execute(db, this->columns); - } + InsertQuery query(this->table_name, this->columns); + // Ugly workaround for non portable stuff + query.body += db.get_returning_id_sql_string(Id::name); + query.execute(db, this->columns); + } + + template + void insert(DatabaseEngine& db, typename std::enable_if && Coucou>::type* = nullptr) + { + InsertQuery query(this->table_name, this->columns); + query.execute(db, this->columns); } void update(DatabaseEngine& db) -- cgit v1.2.3 From 4bd7b6981bb49dd4111c908aaa34c34f677171f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Fri, 13 Apr 2018 23:35:06 +0200 Subject: Refactor that fixes a compilation issue in Release mode Some template specialization were not found, because they were not declared at the point they were used. We moved things around, things are less inter-dependant, and also now it works. --- src/database/row.hpp | 49 ------------------------------------------------- 1 file changed, 49 deletions(-) (limited to 'src/database/row.hpp') diff --git a/src/database/row.hpp b/src/database/row.hpp index 3703ff7..27caf43 100644 --- a/src/database/row.hpp +++ b/src/database/row.hpp @@ -1,9 +1,5 @@ #pragma once -#include -#include -#include - #include #include @@ -29,52 +25,7 @@ struct Row return col.value; } - template - void save(std::unique_ptr& db, typename std::enable_if && Coucou>::type* = nullptr) - { - this->insert(*db); - } - - template - void save(std::unique_ptr& db, typename std::enable_if && Coucou>::type* = nullptr) - { - const Id& id = std::get(this->columns); - if (id.value == Id::unset_value) - { - this->insert(*db); - if (db->last_inserted_rowid >= 0) - std::get(this->columns).value = static_cast(db->last_inserted_rowid); - } - else - this->update(*db); - } - - private: - template - void insert(DatabaseEngine& db, typename std::enable_if && Coucou>::type* = nullptr) - { - InsertQuery query(this->table_name, this->columns); - // Ugly workaround for non portable stuff - query.body += db.get_returning_id_sql_string(Id::name); - query.execute(db, this->columns); - } - - template - void insert(DatabaseEngine& db, typename std::enable_if && Coucou>::type* = nullptr) - { - InsertQuery query(this->table_name, this->columns); - query.execute(db, this->columns); - } - - void update(DatabaseEngine& db) - { - UpdateQuery query(this->table_name, this->columns); - - query.execute(db, this->columns); - } - public: std::tuple columns; std::string table_name; - }; -- cgit v1.2.3 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/row.hpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src/database/row.hpp') 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 From 52166e07acd785b39c0da98be4c35e886b75c3c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Mon, 25 Jun 2018 22:57:13 +0200 Subject: Trivial syntax improvements --- src/database/row.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/database/row.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 columns; + std::tuple columns{}; std::string table_name; private: -- cgit v1.2.3