Delphi Unidac MySQL Create Trigger From Memo Code Syntax Error

269 views Asked by At

Here is my MySQL Trigger code;

DELIMITER //
CREATE TRIGGER pdfdenemeu BEFORE INSERT
ON denemetbl
FOR EACH ROW
BEGIN
  SET NEW.iki =  CONCAT(NEW.bir,'.pdf');
END//
DELIMITER ;

When i run this code on HeidiSQL it creates trigger and works perfectly.

On Delphi XE7 i'm adding a button and a memo to form, putting this code inside of the memo, and button's onclick event is;

sorgu.Close;
sorgu.SQL.Clear;
sorgu.SQL.Add(trim(memo1.text));
sorgu.ExecSQL;

When i click to button, it returns syntax error ; ERROR SCREENSHOT

Also tried as below;

sorgu.Close;
sorgu.SQL.Clear;
sorgu.SQL.Add('DELIMITER //');
sorgu.SQL.Add('CREATE TRIGGER pdfdenemeu BEFORE INSERT');
sorgu.SQL.Add('ON denemetbl');
sorgu.SQL.Add('FOR EACH ROW');
sorgu.SQL.Add('BEGIN');
sorgu.SQL.Add('SET NEW.iki =  CONCAT(NEW.bir,''.pdf'');');
sorgu.SQL.Add('END//');
sorgu.SQL.Add('DELIMITER ;');
sorgu.Execute;

As i mentioned trigger code works without any error on HeidiSQL and MySQL command line, why i'm getting this error message, what am i doing wrong?

1

There are 1 answers

0
Sheshman On BEST ANSWER

As @olivier mentioned DELIMETER is specific to HeidiSQL, i tried to remove delimeter and tried again but didn't solved the problem, but what i did was call the old code with delimeter from my new code, when i thought i removed the delimeter but i wasn't.

So as @olivier mentioned in first post's comment i changed query to this;

CREATE TRIGGER pdfdenemeu BEFORE INSERT ON denemetbl FOR EACH ROW BEGIN SET NEW.iki= CONCAT(NEW.bir,'.pdf'); END;

Worked perfectly. @olivier Thank you, i owe you one.