You are here

class IntColumnHandlerSQLite in Dynamic Entity Reference 8.2

SQLite implementation of denormalizing into integer columns.

Hierarchy

Expanded class hierarchy of IntColumnHandlerSQLite

1 string reference to 'IntColumnHandlerSQLite'
dynamic_entity_reference.services.yml in ./dynamic_entity_reference.services.yml
dynamic_entity_reference.services.yml
1 service uses IntColumnHandlerSQLite
sqlite.dynamic_entity_reference.storage.create_column in ./dynamic_entity_reference.services.yml
Drupal\dynamic_entity_reference\Storage\IntColumnHandlerSQLite

File

src/Storage/IntColumnHandlerSQLite.php, line 8

Namespace

Drupal\dynamic_entity_reference\Storage
View source
class IntColumnHandlerSQLite extends IntColumnHandler {

  /**
   * {@inheritdoc}
   */
  protected function createBody($column_int, $column) {
    return "{$column_int} = CAST({$column} AS INTEGER)";
  }

  /**
   * {@inheritdoc}
   */
  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,
    ]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
IntColumnHandler::$connection protected property The database connection.
IntColumnHandler::allColumnsExist public static function Checks whether all columns exist.
IntColumnHandler::create public function Creates the _int columns and the triggers for them. Overrides IntColumnHandlerInterface::create
IntColumnHandler::delete public function Removes the trigger.
IntColumnHandler::__construct public function IntColumnHandler constructor.
IntColumnHandlerSQLite::createBody protected function Creates the body of the trigger. Overrides IntColumnHandler::createBody
IntColumnHandlerSQLite::createTrigger protected function Actually creates the trigger. Overrides IntColumnHandler::createTrigger