I am stuck in a problem and really hope you can help me. I like to convert a MySQL DATETIME
field into a C++ std::time_t
variable. My database looks like this:
CREATE TABLE data(
id INTEGER AUTO_INCREMENT UNIQUE,
path VARCHAR(1000),
acquisitionDate DATETIME
);
And I am trying to save the value from acquisitionDate
into a c++ variable of type std::time_t
.
After some web searching I learned that I have to use UNIX_TIMESTAMP
in my MySQL statement. However, I did not understand how to actual use it. I can generate a query and receive a sql::ResultSet
:
std::unique_ptr<sql::Statement> stmt(mConnection->createStatement());
std::string query="SELECT id, path, UNIX_TIMESTAMP(acquisitionDate) FROM data WHERE id = 1";
std::unique_ptr<sql::ResultSet> res(stmt->executeQuery(query));
But I don't understand how I can get the actual field value into a std::time_t
variable
if(res->next())
{
std::time_t acquisitionDate = res->getInt("acquisitionDate");
std::time_t acquisitionDate = res->???
}
Somehow my brain does not get this last step. Please help me. Thank you very much!