5

The POCO libraries support MySQL DATE, TIME and DATETIME columns, but not TIMESTAMP. Selecting values from a TIMESTAMP column raises an "unknown field type" exception, since MYSQL_TYPE_TIMESTAMP is not supported in "Poco/Data/MySQL/ResultMetadata.cpp".

In my project I had to change several columns to DATETIME to make it work. This was not a big problem, still I wonder what the reason for this limitation is. If I had to work with an existing database schema that I couldn't alter, I'd be in serious trouble.

Timestamp columns are widely used, hence I don't believe they were simply omitted. Is there an implementation problem as to Timestamp columns? Is there a workaround I could use? Is it planned to add MySQL timestamp support to POCO in the future?

1 Answers1

3

Download the source of POCO libraries then modify the file Data/MySQL/src/ResultMetadata.cpp

std::size_t fieldSize(const MYSQL_FIELD& field)
    /// Convert field MySQL-type and field MySQL-length to actual field length
{
    ...

    case MYSQL_TYPE_DATE:
    case MYSQL_TYPE_TIME:
    case MYSQL_TYPE_DATETIME:
    case MYSQL_TYPE_TIMESTAMP: // <-- add this line
        return sizeof(MYSQL_TIME);

    ...

}   


Poco::Data::MetaColumn::ColumnDataType fieldType(const MYSQL_FIELD& field)
    /// Convert field MySQL-type to Poco-type   
{
    ...

    case MYSQL_TYPE_DATETIME:
    case MYSQL_TYPE_TIMESTAMP: // <-- add this line
        return Poco::Data::MetaColumn::FDT_TIMESTAMP;

    ...

}   

Compile the library and you will have support for TIMESTAMP fields.

Patricklaf
  • 306
  • 1
  • 6
  • Since release 1.12.0, it's now integrated in POCO libraries. See [#2569: Added TIMESTAMP data type support on MySQL #3471](https://github.com/pocoproject/poco/pull/3471/files). – Patricklaf Jul 13 '22 at 08:05