I´m building a C++ application that will be running in Ubuntu and will use Sqlite3 as a database.
One of my goals is to have a C++ class containing time/date fields and store then on database.
In the past I´ve used time_t as the variable type on my class and stored them as INTEGER type on Sqlite3, like:
C++ Class:
class MyClass {
time_t dateTimeInfo;
}
Sqlite3:
CREATE TABLE MYCLASS (....., INTEGER DATETIMEINFO, ...);
That approach allows me to SELECT times with different comparasion operatiors (>, >=, < , <=, ==) with no problems at all, as I´m dealing with simple number. At the user level the time_t is converted to ISO 8601 std::string´s so that I can have a human readable interface.
This works very well except that it does not support millisecods. In my current project I need to support them, so I need to make changes to this.
As far I had studies I undestand I need to use std::chrono::time_point as the class type, as follows:
C++ Class:
class MyClass {
std::chrono::time_point dateTimeInfo;
}
But I really don´t know what data type to use in Sqlite3 and if it will work the same way time_t used to...
Sqlite3:
CREATE TABLE MYCLASS (....., ???? DATETIMEINFO, ...);
My questions:
a) Is std::chrono::time_point the correct option here ?
b) What is the Sqlite3 type equivalent ? Still an INTEGER ?
c) Is this the recommended approach (no boost please, C++11) ?
Thanks for helping.
Aucun commentaire:
Enregistrer un commentaire