/** * @return void */ public function rollBack() { if ($this->transactions == 1) { $this->pdo->rollBack(); } elseif ($this->transactions > 1 && $this->queryGrammar->supportsSavepoints()) { $this->pdo->exec($this->queryGrammar->compileSavepointRollBack('trans' . $this->transactions)); } $this->transactions = max(0, $this->transactions - 1); $this->fireConnectionEvent('rollingBack'); }
/** * @param \Notadd\Foundation\Database\Query\Builder $query * @param string $table * @return string */ protected function compileFrom(Builder $query, $table) { $from = parent::compileFrom($query, $table); if (is_string($query->lock)) { return $from . ' ' . $query->lock; } if (!is_null($query->lock)) { return $from . ' with(rowlock,' . ($query->lock ? 'updlock,' : '') . 'holdlock)'; } return $from; }
/** * @param \Notadd\Foundation\Database\Query\Builder $query * @param array $values * @return string */ public function compileInsert(Builder $query, array $values) { $table = $this->wrapTable($query->from); if (!is_array(reset($values))) { $values = [$values]; } if (count($values) == 1) { return parent::compileInsert($query, reset($values)); } $names = $this->columnize(array_keys(reset($values))); $columns = []; foreach (array_keys(reset($values)) as $column) { $columns[] = '? as ' . $this->wrap($column); } $columns = array_fill(0, count($values), implode(', ', $columns)); return "insert into {$table} ({$names}) select " . implode(' union all select ', $columns); }
/** * @return void */ public function truncate() { foreach ($this->grammar->compileTruncate($this) as $sql => $bindings) { $this->connection->statement($sql, $bindings); } }