diff options
author | louiz’ <louiz@louiz.org> | 2018-04-13 23:35:06 +0200 |
---|---|---|
committer | louiz’ <louiz@louiz.org> | 2018-04-13 23:35:06 +0200 |
commit | 4bd7b6981bb49dd4111c908aaa34c34f677171f4 (patch) | |
tree | 918347adb112c04455e23fcad06626e5635b6ad4 /src/database/save.hpp | |
parent | de8267fa3f4f4e1d61bcf35fb36c6664f520a385 (diff) | |
download | biboumi-4bd7b6981bb49dd4111c908aaa34c34f677171f4.tar.gz biboumi-4bd7b6981bb49dd4111c908aaa34c34f677171f4.tar.bz2 biboumi-4bd7b6981bb49dd4111c908aaa34c34f677171f4.tar.xz biboumi-4bd7b6981bb49dd4111c908aaa34c34f677171f4.zip |
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.
Diffstat (limited to 'src/database/save.hpp')
-rw-r--r-- | src/database/save.hpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/database/save.hpp b/src/database/save.hpp new file mode 100644 index 0000000..4362110 --- /dev/null +++ b/src/database/save.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include <database/update_query.hpp> +#include <database/insert_query.hpp> + +#include <database/engine.hpp> + +#include <database/row.hpp> + +#include <utils/is_one_of.hpp> + +template <typename... T, bool Coucou=true> +void save(Row<T...>& row, DatabaseEngine& db, typename std::enable_if<!is_one_of<Id, T...> && Coucou>::type* = nullptr) +{ + insert(row, db); +} + +template <typename... T, bool Coucou=true> +void save(Row<T...>& row, DatabaseEngine& db, typename std::enable_if<is_one_of<Id, T...> && Coucou>::type* = nullptr) +{ + const Id& id = std::get<Id>(row.columns); + if (id.value == Id::unset_value) + { + insert(row, db); + if (db.last_inserted_rowid >= 0) + std::get<Id>(row.columns).value = static_cast<Id::real_type>(db.last_inserted_rowid); + } + else + update(row, db); +} + |