Page 1 of 1

How to insert database date?

PostPosted: Sun Apr 03, 2016 3:47 am
by behtgod
I want to get dababase datetime when I insert/update date to table and save the datetime to my table .
The sql should likeļ¼š
UPDATE table SET datecol=date('now')

by sqlite.

Is there any way in qxOrm?

Re: How to insert database date?

PostPosted: Mon Apr 04, 2016 12:35 pm
by qxorm
Hello,

You can execute custom SQL queries like this :
Code: Select all
QSqlError err = qx::dao::call_query(qx_query("UPDATE table SET datecol=date('now')"));

More details in the QxOrm manual here : http://www.qxorm.com/qxorm_en/manual.html#manual_3610

About putting a date/time on each insert/update, you could also try to use triggers : http://www.qxorm.com/qxorm_en/manual.html#manual_410
1 solution if you want this behavior for all your persistent classes is to define a base class with a property date, then implement insert/update triggers to put a date value.
Then, triggers (defined in the base class) are called automatically when you insert/update any entities.

Another solution could be to create insert/update triggers on database side.

Re: How to insert database date?

PostPosted: Tue Apr 05, 2016 3:32 am
by behtgod
I got it.Thank you very much.