Creating Trigger in MySQL

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Moehre
Posts: 42
Joined: Fri 11 Nov 2005 11:37

Creating Trigger in MySQL

Post by Moehre » Tue 28 Apr 2009 06:48

Hello!

I have a problem in creating a trigger in mysql using UniQuery Component:

CREATE TRIGGER trtest BEFORE UPDATE OF test FOR EACH ROW
BEGIN
SET NEW.Datum = CURRENT_TIMESTAMP;
END;

After reading some examples of creating triggers in MySQL I realized, that always a special delimiter was declared:

DELIMITER //
CREATE TRIGGER ...
END;//

In SQL Workbench I must use this DELIMITER clause to create the trigger or an error occurs. How can I create a trigger using UniQuery in MySQL?

Thx
Moehre

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Tue 28 Apr 2009 07:34

To create a trigger using TUniQuery you should only set the SQL property to appropriate SQL statement and call the Execute method, like this:

Code: Select all

  UniQuery1.SQL.Clear;
  UniQuery1.SQL.Add('CREATE TRIGGER trtest BEFORE UPDATE ON test FOR EACH ROW ');
  UniQuery1.SQL.Add('BEGIN ');
  UniQuery1.SQL.Add('SET NEW.Datum = CURRENT_TIMESTAMP; ');
  UniQuery1.SQL.Add('END;');
  UniQuery1.Execute;

Moehre
Posts: 42
Joined: Fri 11 Nov 2005 11:37

Post by Moehre » Tue 28 Apr 2009 09:45

That did it! Thank you!

Post Reply