cancel
Showing results for 
Search instead for 
Did you mean: 

Trigger::addStatement should not auto-add semicolon to the end of statement

0 Kudos

Trigger::addStatement should not auto-add semicolon to the end of statement

Feature request from adlogic, posted on GitHub Jun 24, 2016

Steps to reproduce

$trigger = $triggerFactory->create();
$trigger->setTable('some_table');
$trigger->setTime(Trigger::TIME_BEFORE);
$trigger->setEvent(Trigger::EVENT_INSERT);
$trigger->setName('some_trigger');
$trigger->addStatement('/* dummy */');
$setup->getConnection()->createTrigger($trigger);

Expected result

Trigger is successfully created.

Actual result

[PDOException] SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ';END' at line 13

More info

Magento generates following query:

CREATE TRIGGER some_trigger BEFORE INSERT ON some_table FOR EACH ROW
  BEGIN
  /* dummy */;
  END

So, ::addStatement should use some heuristics for auto-adding semicolon after each statement, or doesn't add it at all.

4 Comments
apiuser
New Member

Comment from andimov, posted on GitHub Jun 24, 2016

@adlogic Thank you for reporting this issue! Please, provide the used version. If the problem is actual for a specific tag, please, specify it and be sure that the latest update was used.

apiuser
New Member

Comment from adlogic, posted on GitHub Jun 24, 2016

The problem exists in all M2 versions, including latest dev snapshot.

apiuser
New Member

Comment from andimov, posted on GitHub Jun 24, 2016

@adlogic Which MySQL engine and version do you use?

apiuser
New Member

Comment from adlogic, posted on GitHub Jun 25, 2016

mysqld Ver 5.6.31 for Linux on x86_64 (MySQL Community Server (GPL))