简体   繁体   中英

Delphi Unidac MySQL Create Trigger From Memo Code Syntax Error

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; 错误截图

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM