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

Henri Schwarz il1k3pepsi at gmail.com
Mon Jun 19 03:55:22 EDT 2017


Hi Boris,

thanks for your advice. I didn't use the nullable type so far and as
expected the class member is now "NULL" in the database but still the
default rule doesn't apply. I'll build a small example around this issue to
investigate what's happening.

Kind regards,

Henri

2017-06-15 14:22 GMT+02:00 Boris Kolpackov <boris at codesynthesis.com>:

> 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