[odb-users] Support for boost::posix_time::ptime
Stroud, Sean T
ststrou at sandia.gov
Tue Nov 6 12:56:30 EST 2012
Hi,
According to section “19.5.3 PostgreSQL Database Type Mapping” in the ODB manual, the default mapping for posix_time::ptime is TIMESTAMP. However, the ODB compiler complains about the following:
#ifndef TEST_CLASS_H
#define TEST_CLASS_H
#include <odb/core.hxx>
#include "boost/date_time/posix_time/posix_time.hpp"
#pragma db value
class Test_Class {
public:
Test_Class();
private:
friend class odb::access;
boost::posix_time::ptime m_time;
};
#endif
% odb –d pgsql –q test_class.h
test_class.h:15:30: error: unable to map C++ type '::boost::posix_time::ptime' used in data member 'm_time' to a database type
test_class.h:15:30: info: use '#pragma db type' to specify the database type
To fix this, I tried placing #pragma db type(“timestamp”) on the m_time data member. The odb compiler no longer complained, however when I try to compile the generated code I get errors:
/home/ststrou/ODB2.1_install/include/odb/pgsql/traits.hxx: In static member function ‘static void odb::pgsql::default_value_traits<T, <anonymous> >::set_image(typename odb::pgsql::image_traits<ID>::image_type&, bool&, T) [with T = boost::posix_time::ptime, odb::pgsql::database_type_id ID = id_timestamp]’:
test_class-odb.cxx:83: instantiated from here
/home/ststrou/ODB2.1_install/include/odb/pgsql/traits.hxx:374: error: invalid cast from type ‘boost::posix_time::ptime’ to type ‘long long int’
/home/ststrou/ODB2.1_install/include/odb/pgsql/traits.hxx: In static member function ‘static void odb::pgsql::default_value_traits<T, <anonymous> >::set_value(T&, const typename odb::pgsql::image_traits<ID>::image_type&, bool) [with T = boost::posix_time::ptime, odb::pgsql::database_type_id ID = id_timestamp]’:
test_class-odb.cxx:106: instantiated from here
/home/ststrou/ODB2.1_install/include/odb/pgsql/traits.hxx:365: error: invalid conversion from ‘long long int’ to ‘boost::date_time::special_values’
/home/ststrou/ODB2.1_install/include/odb/pgsql/traits.hxx:365: error: initializing argument 1 of ‘boost::posix_time::ptime::ptime(boost::date_time::special_values)â
It apparently does not know how to map a ptime to a timestamp. What am I doing wrong?
Sean
More information about the odb-users
mailing list