summaryrefslogtreecommitdiff
path: root/src/database/select_query.hpp
diff options
context:
space:
mode:
authorlouiz’ <louiz@louiz.org>2018-04-10 23:33:59 +0200
committerlouiz’ <louiz@louiz.org>2018-04-11 00:25:18 +0200
commit857c7d3972a03cbeebf730d99b924d3710dee6a0 (patch)
tree5bf1ed66ba7ddda3f16a470115cf364a8c7a10cb /src/database/select_query.hpp
parent0cd848e532c8c60ed4f3a5d1e6a3850929f2765b (diff)
downloadbiboumi-857c7d3972a03cbeebf730d99b924d3710dee6a0.tar.gz
biboumi-857c7d3972a03cbeebf730d99b924d3710dee6a0.tar.bz2
biboumi-857c7d3972a03cbeebf730d99b924d3710dee6a0.tar.xz
biboumi-857c7d3972a03cbeebf730d99b924d3710dee6a0.zip
Use a different Date data type
PLEASE backup your database before testing this commit, and report any migration issue. In postgresql, we use timestamp with timezone. In sqlite3 we use REAL (the date is expressed as julianday) This requires a migration of the muclogline_ table: In postgresql it’s pretty simple, we convert all the integer into timestamps With sqlite3, we actually rename the table, create the new one with the correct type, then copy everything to the new table, with a conversion function for the Date_ column, and then we delete the old table. fix #3343
Diffstat (limited to 'src/database/select_query.hpp')
-rw-r--r--src/database/select_query.hpp25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/database/select_query.hpp b/src/database/select_query.hpp
index 743a011..3013dd8 100644
--- a/src/database/select_query.hpp
+++ b/src/database/select_query.hpp
@@ -3,8 +3,8 @@
#include <database/engine.hpp>
#include <database/statement.hpp>
+#include <utils/datetime.hpp>
#include <database/query.hpp>
-#include <logger/logger.hpp>
#include <database/row.hpp>
#include <utils/optional_bool.hpp>
@@ -41,6 +41,14 @@ extract_row_value(Statement& statement, const int i)
return result;
}
+template <typename T>
+typename std::enable_if<std::is_same<DateTime, T>::value, T>::type
+extract_row_value(Statement& statement, const int i)
+{
+ const std::string timestamp = statement.get_column_text(i);
+ return {timestamp};
+}
+
template <std::size_t N=0, typename... T>
typename std::enable_if<N < sizeof...(T), void>::type
extract_row_values(Row<T...>& row, Statement& statement)
@@ -58,6 +66,18 @@ typename std::enable_if<N == sizeof...(T), void>::type
extract_row_values(Row<T...>&, Statement&)
{}
+template <typename ColumnType>
+std::string before_column()
+{
+ return {};
+}
+
+template <typename ColumnType>
+std::string after_column()
+{
+ return {};
+}
+
template <typename... T>
struct SelectQuery: public Query
{
@@ -76,7 +96,8 @@ struct SelectQuery: public Query
using ColumnsType = std::tuple<T...>;
using ColumnType = typename std::remove_reference<decltype(std::get<N>(std::declval<ColumnsType>()))>::type;
- this->body += " " + std::string{ColumnType::name};
+ this->body += " ";
+ this->body += before_column<ColumnType>() + ColumnType::name + after_column<ColumnType>();
if (N < (sizeof...(T) - 1))
this->body += ", ";