[odb-users] Use SQLite functions to create timestamps by default

Boris Kolpackov boris at codesynthesis.com
Thu Jun 15 08:22:34 EDT 2017


Henri Schwarz <il1k3pepsi at gmail.com> writes:

> #pragma db options("DEFAULT CURRENT_TIMESTAMP()")
> date timestamp_; // DEFAULT CURRENT_TIMESTAMP()
> 
> I tried this using SQLite but it doesn't seem to work right. At first I had
> to remove the parentheses at the end (throws exception on schema creation).
> I found out that *date* is a typedef for* long* which is mapped to an
> INTEGER but the SQLite documentation states that CURRENT_TIMESTAMP returns
> a timestring (TEXT).

The example shows how to use the options pragma. The type used for
timestamp is "a date" not anything specific.


> Nevertheless when I change the timestamp_ member in the persistent class to
> *std::string* [...] the column remains empty when I create items in the
> table through ODB.

For the column to be assigned default value it must be unspecified or
NULL on insertion. Try something like this:

#include <odb/nullable.hxx>

#pragma db options("DEFAULT CURRENT_TIMESTAMP()")
odb::nullable<std::string> timestamp_;

Boris



More information about the odb-users mailing list