You are here

protected function IntColumnHandlerSQLite::createTrigger in Dynamic Entity Reference 8.2

Actually creates the trigger.

Parameters

string $trigger: The name of the trigger.

string $op: Either UPDATE or INSERT.

string $prefixed_name: The already prefixed table table.

string $body: The body of the trigger.

Overrides IntColumnHandler::createTrigger

File

src/Storage/IntColumnHandlerSQLite.php, line 20

Class

IntColumnHandlerSQLite
SQLite implementation of denormalizing into integer columns.

Namespace

Drupal\dynamic_entity_reference\Storage

Code

protected function createTrigger($trigger, $op, $prefixed_name, $body) {
  $parts = explode('.', $prefixed_name);

  // Simpletest for example prefixes with a database name but SQLite does
  // not support referencing databases in the body of the trigger (even if it
  // is the same database the triggering table is in).
  $table_name = array_pop($parts);
  $query = "\n        CREATE TRIGGER {$trigger} AFTER {$op} ON {$prefixed_name}\n        FOR EACH ROW\n        BEGIN\n          UPDATE {$table_name} SET {$body} WHERE ROWID=NEW.ROWID";

  // SQLite requires a ; in the query which requires bypassing Drupal's built
  // in single statement only protection. Although this method is not
  // supposed to be called by user submitted data.
  if (strpos($query, ';') !== FALSE) {
    throw new \InvalidArgumentException('; is not supported in SQL strings. Use only one statement at a time.');
  }
  $this->connection
    ->query("{$query}; END", [], [
    'allow_delimiter_in_query' => TRUE,
  ]);
}