[odb-users] unable to map C++ type '::std::chrono::duration< double >'

Paul Stath PStath at jmawireless.com
Thu Sep 12 12:33:11 EDT 2019

Sorry, forgot to CC mailing list.

-----Original Message-----
From: Paul Stath 
Sent: Thursday, September 12, 2019 12:31 PM
To: Monika Idzik <moni.idzik at gmail.com>
Subject: RE: [odb-users] unable to map C++ type '::std::chrono::duration< double >'

Hi Monika,

You should always include the definition for the class you are trying to map.  (If proprietary, then create a similar test class that exhibits the same problem.)

Firstly, do you really wish to store a std::chrono::duration attribute in your data object?
Normally, I would have a std::chrono::time_point attribute, since I want to store a point in time.

Are you really trying to store a time duration (difference between two timepoints)?

The second question is what time precision do you need in your data object?
If you only need 1 second precision, then I would suggest the following:

Use boost::posix_time::ptime as your timestamp variable and include the boost profile.

Make this a private class variable (timestamp_) and provide getter/setter class methods that allow you to get/set the attribute.
You can overload the setTimestamp() method to set the value of the timestamp attribute using whatever time/date datatype you need.
Getting the timestamp in different time/data datatypes would require multiple getter methods.

--- Paul

-----Original Message-----
From: Monika Idzik <moni.idzik at gmail.com> 
Sent: Wednesday, September 11, 2019 8:06 PM
To: odb-users at codesynthesis.com
Subject: [odb-users] unable to map C++ type '::std::chrono::duration< double >'

Dear odb Users,

I'm getting an error:

error: unable to map C++ type '::std::chrono::duration< double >' used in data member 'test_chrono' to a MySQL database type

when trying to declare the variable of type std::chrono::duration<double>.
I know I could use boost::posix_time::time_duration with boost profile, but I want to be able to add also std::chrono variables. Is there a way to do this?

Thank you,

More information about the odb-users mailing list