/** * @param string $sql * @param \Notadd\Foundation\Database\Connection $connection * @param \Notadd\Foundation\Database\Schema\Blueprint $blueprint * @return string */ protected function compileCreateEncoding($sql, Connection $connection, Blueprint $blueprint) { if (isset($blueprint->charset)) { $sql .= ' default character set ' . $blueprint->charset; } elseif (!is_null($charset = $connection->getConfig('charset'))) { $sql .= ' default character set ' . $charset; } if (isset($blueprint->collation)) { $sql .= ' collate ' . $blueprint->collation; } elseif (!is_null($collation = $connection->getConfig('collation'))) { $sql .= ' collate ' . $collation; } return $sql; }
/** * @param \Closure $callback * @return mixed * @throws \Throwable */ public function transaction(Closure $callback) { if ($this->getDriverName() == 'sqlsrv') { return parent::transaction($callback); } $this->pdo->exec('BEGIN TRAN'); try { $result = $callback($this); $this->pdo->exec('COMMIT TRAN'); } catch (Exception $e) { $this->pdo->exec('ROLLBACK TRAN'); throw $e; } catch (Throwable $e) { $this->pdo->exec('ROLLBACK TRAN'); throw $e; } return $result; }
/** * @param \Notadd\Foundation\Database\Schema\Blueprint $blueprint * @param \Illuminate\Support\Fluent $command * @param \Notadd\Foundation\Database\Connection $connection * @return array * @throws \Doctrine\DBAL\DBALException */ public function compileChange(Blueprint $blueprint, Fluent $command, Connection $connection) { if (!$connection->isDoctrineAvailable()) { throw new RuntimeException(sprintf('Changing columns for table "%s" requires Doctrine DBAL; install "doctrine/dbal".', $blueprint->getTable())); } $schema = $connection->getDoctrineSchemaManager(); $tableDiff = $this->getChangedDiff($blueprint, $schema); if ($tableDiff !== false) { return (array) $schema->getDatabasePlatform()->getAlterTableSQL($tableDiff); } return []; }
/** * @param mixed $value * @return \Notadd\Foundation\Database\Query\Expression */ public function raw($value) { return $this->connection->raw($value); }
/** * @param \Notadd\Foundation\Database\Connection $connection * @param string $type * @return \Notadd\Foundation\Database\Connection */ protected function setPdoForType(Connection $connection, $type = null) { if ($type == 'read') { $connection->setPdo($connection->getReadPdo()); } elseif ($type == 'write') { $connection->setReadPdo($connection->getPdo()); } return $connection; }
/** * @param \Notadd\Foundation\Database\Schema\Blueprint $blueprint * @param \Illuminate\Support\Fluent $command * @param \Notadd\Foundation\Database\Connection $connection * @return array */ public function compileDropColumn(Blueprint $blueprint, Fluent $command, Connection $connection) { $schema = $connection->getDoctrineSchemaManager(); $tableDiff = $this->getDoctrineTableDiff($blueprint, $schema); foreach ($command->columns as $name) { $column = $connection->getDoctrineColumn($blueprint->getTable(), $name); $tableDiff->removedColumns[$name] = $column; } return (array) $schema->getDatabasePlatform()->getAlterTableSQL($tableDiff); }
/** * @param string $table * @return array */ public function getColumnListing($table) { $table = $this->connection->getTablePrefix() . $table; $results = $this->connection->select($this->grammar->compileColumnExists($table)); return $this->connection->getPostProcessor()->processColumnListing($results); }