/** * 回滚事务 * * @return void */ protected function rollBack() { if ($this->transactions == 1) { $this->getPdo()->rollBack(); } elseif ($this->transactions > 1 && $this->grammar->supportsSavepoints()) { $this->getPdo()->exec($this->grammar->compileSavepointRollBack('trans' . $this->transactions)); } $this->transactions = max(0, $this->transactions - 1); $this->callConnectionEvent('rollingBack'); }
/** * 编译update语句 * * @param CatLib\Database\Grammars\Builder $query * @param array $values * @return string */ public function compileUpdate(Builder $query, $values) { $sql = parent::compileUpdate($query, $values); if (isset($query->orders)) { $sql .= ' ' . $this->compileOrders($query, $query->orders); } if (isset($query->limit)) { $sql .= ' ' . $this->compileLimit($query, $query->limit); } return rtrim($sql); }
/** * 编译插入语句 * * @param \CatLib\Database\Grammars\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); }
/** * 向语法编译器设定表前缀 * * @param \CatLib\Database\Grammars\Grammar $grammar * @return \CatLib\Database\Grammars\Grammar */ public function withTablePrefix(Grammar $grammar) { $param = $this->getConfig("prefix"); if ($param != null) { $grammar->setTablePrefix($param); } return $grammar; }
/** * 清空数据库 * * @return void */ public function truncate() { foreach ($this->grammar->compileTruncate($this) as $sql => $bindings) { $this->connection->statement($sql, $bindings); } }
/** * 包装表 * * @param \CatLib\Database\Grammars\Expression|string $table * @return string */ public function wrapTable($table) { return $this->wrapTableValuedFunction(parent::wrapTable($table)); }