How to auto populate on DateTime on insert or update?

Discussion of open issues, suggestions and bugs regarding LiteDAC (SQLite Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Steven
Posts: 30
Joined: Fri 06 Dec 2013 19:48

How to auto populate on DateTime on insert or update?

Post by Steven » Tue 07 Jan 2014 21:45

Using Delphi Xe2 and v2.2.5 of LiteDAC Professional and can't seem to figure how to auto populate a DateTime field when inserting a new record into my SQLite table.

For example when using the DBNavigator control to Insert & Post or Edit & Post, etc.

I'm using TLiteQuery, TLiteDataSource along with TCRDDBGrid.
My form also has various DB Control controls like TDBEdit and DBNavigator.

I tried researching online and attaching code to the various events in the controls but I am still stumped.

Edit:
I was assuming that I could do this via code, is this something that must be done using triggers?

Any help would be appreciated.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: How to auto populate on DateTime on insert or update?

Post by AlexP » Thu 09 Jan 2014 12:36

Hello,

In order for the field to be filled in automatically on inserting a new record, you should set the default value for this field on table creation, as well as enable the DefaultValues option

Code: Select all

CREATE TABLE test (id INT,  data TIMESTAMP DEFAULT current_timestamp);

Code: Select all

LiteQuery1.Options.DefaultValues := True;

Post Reply