Firebird Trigger to Insert Current Date for Two Fields (CreationDate & ModifyDate)

Hello. I am using LibreOffice Base 7.5 (Firebird Embedded) on a Windows 10 Desktop (64-bit).
.
I created a new database using Firebird Embedded (instead of my previous use of HSQLDB). I need to update two fields with the current date:
.
Table: tblProjects

  • fldCreationDate - the date the record was created.
  • fldModifyDate - the date the record was modified.
    .

I was advised that a “Trigger” would actually work better with a Firebird Embedded database.
.
@Ratslinger kindly provided a sample demo that did EXACTLY what I wanted (Need Date fields that automatically insert the date that record was created and updated - #12 by Ratslinger), BUT he said he used the following code from @mariosv to create these two fields when the Table was FIRST CREATED:

create table MyData (
  id int not null primary key,
  record_created timestamp default current_timestamp,
  ...
)

.
MY QUESTIONS:

  • My table is ALREADY created with many fields… so should I delete only these two fields and recreate the two fields using the code?

  • If I must start over, is the following the correct code for my particular situation:

create table "tblProjects" (
  id int not null primary key,
  "fldCreationDate" timestamp default current_timestamp,
  "fldModifyDate" timestamp default current_timestamp
)

.

  • I assume that I will enter the above code in Tools > SQL (Command to Execute)?
    .
  • Is there any way to view the SQL commands that have already been entered previously? I tried to view the code that was used in the FirebirdTriggerSample.odb demo that @Ratslinger used… but couldn’t figure out how to see it. :slightly_smiling_face:

THANKS for any help at all…

Hello,
Use a copy of your Base file to test changes. Altering the table should work.
.
As for the commands used, you must not have looked at the answer or sample too closely. I stated:

Used SQL from @mariosv as basis to create table and Code from one of the links I posted for a Trigger. The code for each is saved in Queries within the sample (cannot execute from there - only from Tools SQL).

.
and in the query section is:


.
If I were doing this, I’d create a new table, then copy data (copy & paste or SQL) from the old table to the new table & test.
.
Make sure you have a backup before doing anything. It is fairly simple.
.

My above quote from previous answer also states this to be true.
.

No. Please look at what is shown. In the sample provided for create table, there is no default for the modify date, If there were, it would place a date in there when the record was new.

It worked! THANK YOU!
.
You were right… I did not notice the Query section. I was looking for the SQL commands you used under the “Previous Commands” drop-down on the SQL Command window. :upside_down_face:
.
Which makes me ask: Is there any way to go back and see a list of commands that were previously executed?

A history. None I know of.

1 Like