/** * @return array */ protected function switchStatements() { $originTableName = $this->adapter->quoteTableName($this->origin->getName()); $destinationTableName = $this->adapter->quoteTableName($this->destination->getName()); $archiveName = $this->adapter->quoteTableName($this->options['archive_name']); return ["LOCK TABLE {$originTableName} write, {$destinationTableName} write", "ALTER TABLE {$originTableName} rename {$archiveName}", "ALTER TABLE {$destinationTableName} rename {$originTableName}", 'COMMIT', 'UNLOCK TABLES']; }
/** * @return array */ protected function statements() { $originTableName = $this->adapter->quoteTableName($this->origin->getName()); $destinationTableName = $this->adapter->quoteTableName($this->destination->getName()); $archiveName = $this->adapter->quoteTableName($this->options['archive_name']); return ["RENAME TABLE {$originTableName} TO {$archiveName}, {$destinationTableName} TO {$originTableName}"]; }
/** * @param integer $lowest * @param integer $highest * @return string */ protected function copy($lowest, $highest) { $originName = $this->adapter->quoteTableName($this->origin->getName()); $destinationName = $this->adapter->quoteTableName($this->destination->getName()); $destinationColumns = implode(',', $this->sqlHelper->quoteColumns($this->intersection->destination())); $originColumns = implode(',', $this->sqlHelper->typedColumns($originName, $this->sqlHelper->quoteColumns($this->intersection->origin()))); return implode(" ", ["INSERT IGNORE INTO {$destinationName} ({$destinationColumns})", "SELECT {$originColumns} FROM {$originName}", "WHERE {$originName}.{$this->primaryKey} BETWEEN {$lowest} AND {$highest}"]); }
/** * @return string */ protected function createDeleteTrigger() { $name = $this->trigger('delete'); $primaryKey = $this->sqlHelper->extractPrimaryKey($this->origin); if (empty($primaryKey)) { throw new \RuntimeException("Table `{$this->origin->getName()}` does not have a primary key."); } $primaryKey = $this->sqlHelper->quoteColumn($primaryKey); $originName = $this->adapter->quoteTableName($this->origin->getName()); $destinationName = $this->adapter->quoteTableName($this->destination->getName()); return implode("\n ", ["CREATE TRIGGER {$name}", "AFTER DELETE ON {$originName} FOR EACH ROW", "DELETE IGNORE FROM {$destinationName} {$this->sqlHelper->annotation()}", "WHERE {$destinationName}.{$primaryKey} = OLD.{$primaryKey}"]); }
/** * Quotes a table name for use in a query. * * @param string $tableName Table Name * @return string */ public function quoteTableName($tableName) { return $this->adapter->quoteTableName($tableName); }