Beispiel #1
0
 /**
  * Test case for getName()
  *
  * @expectedException \Zend_Db_Exception
  * @expectedExceptionMessage Trigger name is not defined
  */
 public function testGetNameWithException()
 {
     $tableName = 'TEST_TABLE_NAME_' . mt_rand(100, 999);
     $event = \Magento\Framework\DB\Ddl\Trigger::EVENT_INSERT;
     $this->_object->setTable($tableName)->setTime(\Magento\Framework\DB\Ddl\Trigger::TIME_AFTER)->setEvent($event);
     $this->_object->getName();
 }
Beispiel #2
0
 /**
  * Create trigger
  *
  * @param \Magento\Framework\DB\Ddl\Trigger $trigger
  * @throws ErrorException
  * @return StatementInterface
  */
 public function createTrigger(\Magento\Framework\DB\Ddl\Trigger $trigger)
 {
     if (!$trigger->getStatements()) {
         throw new ErrorException(sprintf(__('Trigger %s has not statements available'), $trigger->getName()));
     }
     $statements = implode("\n", $trigger->getStatements());
     $sql = sprintf("CREATE TRIGGER %s %s %s ON %s FOR EACH ROW\nBEGIN\n%s\nEND", $trigger->getName(), $trigger->getTime(), $trigger->getEvent(), $trigger->getTable(), $statements);
     return $this->query($sql);
 }
Beispiel #3
0
    /**
     * Create trigger
     *
     * @param \Magento\Framework\DB\Ddl\Trigger $trigger
     * @throws \Zend_Db_Exception
     * @return \Zend_Db_Statement_Pdo
     */
    public function createTrigger(\Magento\Framework\DB\Ddl\Trigger $trigger)
    {
        if (!$trigger->getStatements()) {
            throw new \Zend_Db_Exception(
                (string)new \Magento\Framework\Phrase(
                    'Trigger %1 has not statements available',
                    [$trigger->getName()]
                )
            );
        }

        $statements = implode("\n", $trigger->getStatements());

        $sql = sprintf(
            "CREATE TRIGGER %s %s %s ON %s FOR EACH ROW\nBEGIN\n%s\nEND",
            $trigger->getName(),
            $trigger->getTime(),
            $trigger->getEvent(),
            $trigger->getTable(),
            $statements
        );

        return $this->multiQuery($sql);
    }