How to insert database date?

Forum for posting problems using QxOrm library

How to insert database date?

Postby behtgod » Sun Apr 03, 2016 3:47 am

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?
behtgod
 
Posts: 18
Joined: Mon Nov 16, 2015 8:21 am

Re: How to insert database date?

Postby qxorm » Mon Apr 04, 2016 12:35 pm

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.
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: How to insert database date?

Postby behtgod » Tue Apr 05, 2016 3:32 am

I got it.Thank you very much.
behtgod
 
Posts: 18
Joined: Mon Nov 16, 2015 8:21 am


Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 9 guests