Actions
Bug #6075
open[Wt::Dbo] Add built-in type support for std::chrono::time_point and std::chrono::seconds
Start date:
10/30/2017
Due date:
% Done:
0%
Estimated time:
Description
I use them in my AccessToken entity class:
std::chrono::system_clock::time_point mCreatedOn {std::chrono::system_clock::now()};
std::chrono::seconds mExpiresIn {3600};
Updated by Oleg Artenii about 7 years ago
So chrono::time_point
works but chrono::seconds
doesnt:
include/Wt/Dbo/Field_impl.h:48:35: error: ‘type’ is not a member of ‘Wt::Dbo::sql_value_traits<std::chrono::duration<long int>, void>’
return sql_value_traits<V>::type(session.connection(false), size_);
~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Updated by Oleg Artenii about 7 years ago
chrono::time_point is created as text column. I expected it to be timestamp/uint.
P.S. Sorry for flood but I can't edit comments.
Updated by Oleg Artenii about 7 years ago
When I try to specialize that trait I get error:
error: no matching function for call to ‘Wt::Dbo::SqlStatement::getResult(int&, std::chrono::seconds*)’
if (statement->getResult(column, &v)) {
^
In file included from /home/i/cpp/.../src/storage/wtDboCustomTypes.h:11:0,
from /home/i/cpp/.../src/storage/wtDboCustomTypes.cpp:9:
/home/i/cpp/.../cmake-build-debug/external-projects/installed/include/Wt/Dbo/SqlStatement.h:129:16: note: candidate: virtual bool Wt::Dbo::SqlStatement::getResult(int, std::__cxx11::string*, int)
virtual bool getResult(int column, std::string *value, int size) = 0;
^~~~~~~~~
/home/i/cpp/.../cmake-build-debug/external-projects/installed/include/Wt/Dbo/SqlStatement.h:129:16: note: candidate expects 3 arguments, 2 provided
/home/i/cpp/.../cmake-build-debug/external-projects/installed/include/Wt/Dbo/SqlStatement.h:135:16: note: candidate: virtual bool Wt::Dbo::SqlStatement::getResult(int, short int*)
virtual bool getResult(int column, short *value) = 0;
^~~~~~~~~
/home/i/cpp/.../cmake-build-debug/external-projects/installed/include/Wt/Dbo/SqlStatement.h:135:16: note: no known conversion for argument 2 from ‘std::chrono::seconds* {aka std::chrono::duration<long int>*}’ to ‘short int*’
/home/i/cpp/.../cmake-build-debug/external-projects/installed/include/Wt/Dbo/SqlStatement.h:141:16: note: candidate: virtual bool Wt::Dbo::SqlStatement::getResult(int, int*)
virtual bool getResult(int column, int *value) = 0;
^~~~~~~~~
/home/i/cpp/.../cmake-build-debug/external-projects/installed/include/Wt/Dbo/SqlStatement.h:141:16: note: no known conversion for argument 2 from ‘std::chrono::seconds* {aka std::chrono::duration<long int>*}’ to ‘int*’
/home/i/cpp/.../cmake-build-debug/external-projects/installed/include/Wt/Dbo/SqlStatement.h:147:16: note: candidate: virtual bool Wt::Dbo::SqlStatement::getResult(int, long long int*)
virtual bool getResult(int column, long long *value) = 0;
^~~~~~~~~
/home/i/cpp/.../cmake-build-debug/external-projects/installed/include/Wt/Dbo/SqlStatement.h:147:16: note: no known conversion for argument 2 from ‘std::chrono::seconds* {aka std::chrono::duration<long int>*}’ to ‘long long int*’
/home/i/cpp/.../cmake-build-debug/external-projects/installed/include/Wt/Dbo/SqlStatement.h:153:16: note: candidate: virtual bool Wt::Dbo::SqlStatement::getResult(int, float*)
virtual bool getResult(int column, float *value) = 0;
^~~~~~~~~
/home/i/cpp/.../cmake-build-debug/external-projects/installed/include/Wt/Dbo/SqlStatement.h:153:16: note: no known conversion for argument 2 from ‘std::chrono::seconds* {aka std::chrono::duration<long int>*}’ to ‘float*’
/home/i/cpp/.../cmake-build-debug/external-projects/installed/include/Wt/Dbo/SqlStatement.h:159:16: note: candidate: virtual bool Wt::Dbo::SqlStatement::getResult(int, double*)
virtual bool getResult(int column, double *value) = 0;
^~~~~~~~~
/home/i/cpp/.../cmake-build-debug/external-projects/installed/include/Wt/Dbo/SqlStatement.h:159:16: note: no known conversion for argument 2 from ‘std::chrono::seconds* {aka std::chrono::duration<long int>*}’ to ‘double*’
/home/i/cpp/.../cmake-build-debug/external-projects/installed/include/Wt/Dbo/SqlStatement.h:165:16: note: candidate: virtual bool Wt::Dbo::SqlStatement::getResult(int, std::chrono::_V2::system_clock::time_point*, Wt::Dbo::SqlDateTimeType)
virtual bool getResult(int column, std::chrono::system_clock::time_point *value,
^~~~~~~~~
/home/i/cpp/.../cmake-build-debug/external-projects/installed/include/Wt/Dbo/SqlStatement.h:165:16: note: candidate expects 3 arguments, 2 provided
/home/i/cpp/.../cmake-build-debug/external-projects/installed/include/Wt/Dbo/SqlStatement.h:172:16: note: candidate: virtual bool Wt::Dbo::SqlStatement::getResult(int, std::chrono::duration<int, std::ratio<1l, 1000l> >*)
virtual bool getResult(int column, std::chrono::duration<int, std::milli> *value)
^~~~~~~~~
/home/i/cpp/.../cmake-build-debug/external-projects/installed/include/Wt/Dbo/SqlStatement.h:172:16: note: no known conversion for argument 2 from ‘std::chrono::seconds* {aka std::chrono::duration<long int>*}’ to ‘std::chrono::duration<int, std::ratio<1l, 1000l> >*’
/home/i/cpp/.../cmake-build-debug/external-projects/installed/include/Wt/Dbo/SqlStatement.h:179:16: note: candidate: virtual bool Wt::Dbo::SqlStatement::getResult(int, std::vector<unsigned char>*, int)
virtual bool getResult(int column, std::vector<unsigned char> *value,
^~~~~~~~~
/home/i/cpp/.../cmake-build-debug/external-projects/installed/include/Wt/Dbo/SqlStatement.h:179:16: note: candidate expects 3 arguments, 2 provided
^
#include <Wt/Dbo/SqlTraits.h>
#include <Wt/Dbo/SqlConnection.h>
#include <Wt/Dbo/SqlStatement.h>
#include <chrono>
namespace Wt { namespace Dbo {
template<>
class WTDBO_API sql_value_traits<std::chrono::seconds, void>
{
static const bool specialized = true;
static std::string type(SqlConnection *conn, int size);
static void bind(const std::chrono::seconds& v, SqlStatement *statement, int column, int size);
static bool read(std::chrono::seconds& v, SqlStatement *statement, int column, int size);
};
}}
namespace Wt { namespace Dbo {
std::string sql_value_traits<std::chrono::seconds>::type(SqlConnection *conn, int size)
{
return conn->dateTimeType(SqlDateTimeType::Time);
}
void sql_value_traits<std::chrono::seconds>::bind(
const std::chrono::seconds& v,
SqlStatement *statement,
int column,
int size
) {
if (v == std::chrono::seconds::zero()) {
statement->bindNull(column);
} else {
statement->bind(column, v);
}
}
bool sql_value_traits<std::chrono::seconds>::read(
std::chrono::seconds& v,
SqlStatement *statement,
int column,
int size
) {
if (statement->getResult(column, &v)) {
return true;
} else {
v = std::chrono::seconds::zero();
return false;
}
}
}}
Updated by Roel Standaert about 7 years ago
std::chrono::seconds
is not supported, but std::chrono::duration<int, std::milli>
is, which of course does have a shorter range. I'm not really sure why duration<int, std::milli>
was chosen, I'll have to look into that.
Actions