/** * @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 createUpdateTrigger() { $destinationColumns = implode(',', $this->sqlHelper->quoteColumns($this->intersection->destination())); $originColumns = implode(',', $this->sqlHelper->typedColumns('NEW', $this->sqlHelper->quoteColumns($this->intersection->origin()))); $name = $this->trigger('update'); $originName = $this->adapter->quoteTableName($this->origin->getName()); $destinationName = $this->adapter->quoteTableName($this->destination->getName()); return implode("\n ", ["CREATE TRIGGER {$name}", "AFTER UPDATE ON {$originName} FOR EACH ROW", "REPLACE INTO {$destinationName} ({$destinationColumns}) {$this->sqlHelper->annotation()}", "VALUES ({$originColumns})"]); }
public function testOriginRenamed() { $this->destination->expects($this->atLeastOnce())->method('getRenamedColumns')->will($this->returnValue(['something' => 'something_else'])); $this->assertEquals(['id', 'name', 'something'], $this->intersection->origin()); }