diff --git a/src/Database/Connections/Connection.php b/src/Database/Connections/Connection.php index ac55061f5..917946d62 100644 --- a/src/Database/Connections/Connection.php +++ b/src/Database/Connections/Connection.php @@ -4,7 +4,7 @@ use Illuminate\Database\Connection as ConnectionBase; /** - * Connection base class + * @deprecated see \October\Rain\Database\Connections\ExtendsConnection */ class Connection extends ConnectionBase { diff --git a/src/Database/Connections/ExtendsConnection.php b/src/Database/Connections/ExtendsConnection.php new file mode 100644 index 000000000..383cc227e --- /dev/null +++ b/src/Database/Connections/ExtendsConnection.php @@ -0,0 +1,54 @@ +getQueryGrammar(), + $this->getPostProcessor() + ); + } + + /** + * logQuery in the connection's query log + * @param string $query + * @param array $bindings + * @param float|null $time + * @return void + */ + public function logQuery($query, $bindings, $time = null) + { + if (isset($this->events)) { + $this->events->dispatch('illuminate.query', [$query, $bindings, $time, $this->getName()]); + } + + parent::logQuery($query, $bindings, $time); + } + + /** + * fireConnectionEvent for this connection + * @param string $event + * @return void + */ + protected function fireConnectionEvent($event) + { + if (isset($this->events)) { + $this->events->dispatch('connection.'.$this->getName().'.'.$event, $this); + } + + parent::fireConnectionEvent($event); + } +} \ No newline at end of file diff --git a/src/Database/Connections/MySqlConnection.php b/src/Database/Connections/MySqlConnection.php index dfa741419..25913714d 100644 --- a/src/Database/Connections/MySqlConnection.php +++ b/src/Database/Connections/MySqlConnection.php @@ -1,173 +1,11 @@ run($query, $bindings, function ($query, $bindings) use ($sequence) { - if ($this->pretending()) { - return true; - } - - $statement = $this->getPdo()->prepare($query); - - $this->bindValues($statement, $this->prepareBindings($bindings)); - - $this->recordsHaveBeenModified(); - - $result = $statement->execute(); - - $this->lastInsertId = $this->getPdo()->lastInsertId($sequence); - - return $result; - }); - } - - /** - * Get the last insert ID. - * - * @return int - */ - public function getLastInsertId() - { - return $this->lastInsertId; - } - - /** - * Escape a binary value for safe SQL embedding. - * - * @param string $value - * @return string - */ - protected function escapeBinary($value) - { - $hex = bin2hex($value); - - return "x'{$hex}'"; - } - - /** - * Determine if the given database exception was caused by a unique constraint violation. - * - * @param \Exception $exception - * @return bool - */ - protected function isUniqueConstraintError(Exception $exception) - { - return boolval(preg_match('#Integrity constraint violation: 1062#i', $exception->getMessage())); - } - - /** - * Determine if the connected database is a MariaDB database. - * - * @return bool - */ - public function isMaria() - { - return str_contains($this->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION), 'MariaDB'); - } - - /** - * Get the default query grammar instance. - * - * @return \Illuminate\Database\Query\Grammars\MySqlGrammar - */ - protected function getDefaultQueryGrammar() - { - $grammar = new QueryGrammar; - if (method_exists($grammar, 'setConnection')) { - $grammar->setConnection($this); - } - - return $this->withTablePrefix($grammar); - } - - /** - * Get a schema builder instance for the connection. - * - * @return \Illuminate\Database\Schema\MySqlBuilder - */ - public function getSchemaBuilder() - { - if (is_null($this->schemaGrammar)) { - $this->useDefaultSchemaGrammar(); - } - - return new MySqlBuilder($this); - } - - /** - * Get the default schema grammar instance. - * - * @return \Illuminate\Database\Schema\Grammars\MySqlGrammar - */ - protected function getDefaultSchemaGrammar() - { - $grammar = new SchemaGrammar; - if (method_exists($grammar, 'setConnection')) { - $grammar->setConnection($this); - } - - return $this->withTablePrefix($grammar); - } - - /** - * Get the schema state for the connection. - * - * @param \Illuminate\Filesystem\Filesystem|null $files - * @param callable|null $processFactory - * @return \Illuminate\Database\Schema\MySqlSchemaState - */ - public function getSchemaState(Filesystem $files = null, callable $processFactory = null) - { - return new MySqlSchemaState($this, $files, $processFactory); - } - - /** - * Get the default post processor instance. - * - * @return \Illuminate\Database\Query\Processors\MySqlProcessor - */ - protected function getDefaultPostProcessor() - { - return new MySqlProcessor; - } - - /** - * Get the Doctrine DBAL driver. - * - * @return \Illuminate\Database\PDO\MySqlDriver - */ - protected function getDoctrineDriver() - { - return new MySqlDriver; - } + use \October\Rain\Database\Connections\ExtendsConnection; } diff --git a/src/Database/Connections/PostgresConnection.php b/src/Database/Connections/PostgresConnection.php index 9bcca4dde..87adb4864 100644 --- a/src/Database/Connections/PostgresConnection.php +++ b/src/Database/Connections/PostgresConnection.php @@ -1,105 +1,11 @@ $value) { - if (is_int($value)) { - $pdoParam = PDO::PARAM_INT; - } elseif (is_resource($value)) { - $pdoParam = PDO::PARAM_LOB; - } else { - $pdoParam = PDO::PARAM_STR; - } - - $statement->bindValue( - is_string($key) ? $key : $key + 1, - $value, - $pdoParam - ); - } - } - - /** - * Get the default query grammar instance. - * - * @return \Illuminate\Database\Query\Grammars\PostgresGrammar - */ - protected function getDefaultQueryGrammar() - { - return $this->withTablePrefix(new QueryGrammar); - } - - /** - * Get a schema builder instance for the connection. - * - * @return \Illuminate\Database\Schema\PostgresBuilder - */ - public function getSchemaBuilder() - { - if (is_null($this->schemaGrammar)) { - $this->useDefaultSchemaGrammar(); - } - - return new PostgresBuilder($this); - } - - /** - * Get the default schema grammar instance. - * - * @return \Illuminate\Database\Schema\Grammars\PostgresGrammar - */ - protected function getDefaultSchemaGrammar() - { - return $this->withTablePrefix(new SchemaGrammar); - } - - /** - * Get the schema state for the connection. - * - * @param \Illuminate\Filesystem\Filesystem|null $files - * @param callable|null $processFactory - * @return \Illuminate\Database\Schema\PostgresSchemaState - */ - public function getSchemaState(Filesystem $files = null, callable $processFactory = null) - { - return new PostgresSchemaState($this, $files, $processFactory); - } - - /** - * Get the default post processor instance. - * - * @return \Illuminate\Database\Query\Processors\PostgresProcessor - */ - protected function getDefaultPostProcessor() - { - return new PostgresProcessor; - } - - /** - * Get the Doctrine DBAL driver. - * - * @return \Illuminate\Database\PDO\PostgresDriver - */ - protected function getDoctrineDriver() - { - return new PostgresDriver; - } + use \October\Rain\Database\Connections\ExtendsConnection; } diff --git a/src/Database/Connections/SQLiteConnection.php b/src/Database/Connections/SQLiteConnection.php index b444beca5..0c5a32492 100644 --- a/src/Database/Connections/SQLiteConnection.php +++ b/src/Database/Connections/SQLiteConnection.php @@ -1,113 +1,11 @@ getForeignKeyConstraintsConfigurationValue(); - - if ($enableForeignKeyConstraints === null) { - return; - } - - $enableForeignKeyConstraints - ? $this->getSchemaBuilder()->enableForeignKeyConstraints() - : $this->getSchemaBuilder()->disableForeignKeyConstraints(); - } - - /** - * Get the default query grammar instance. - * - * @return \Illuminate\Database\Query\Grammars\SQLiteGrammar - */ - protected function getDefaultQueryGrammar() - { - return $this->withTablePrefix(new QueryGrammar); - } - - /** - * Get a schema builder instance for the connection. - * - * @return \Illuminate\Database\Schema\SQLiteBuilder - */ - public function getSchemaBuilder() - { - if (is_null($this->schemaGrammar)) { - $this->useDefaultSchemaGrammar(); - } - - return new SQLiteBuilder($this); - } - - /** - * Get the default schema grammar instance. - * - * @return \Illuminate\Database\Schema\Grammars\SQLiteGrammar - */ - protected function getDefaultSchemaGrammar() - { - return $this->withTablePrefix(new SchemaGrammar); - } - - /** - * Get the schema state for the connection. - * - * @param \Illuminate\Filesystem\Filesystem|null $files - * @param callable|null $processFactory - * - * @throws \RuntimeException - */ - public function getSchemaState(Filesystem $files = null, callable $processFactory = null) - { - return new SqliteSchemaState($this, $files, $processFactory); - } - - /** - * Get the default post processor instance. - * - * @return \Illuminate\Database\Query\Processors\SQLiteProcessor - */ - protected function getDefaultPostProcessor() - { - return new SQLiteProcessor; - } - - /** - * Get the Doctrine DBAL driver. - * - * @return \Illuminate\Database\PDO\SQLiteDriver - */ - protected function getDoctrineDriver() - { - return new SQLiteDriver; - } - - /** - * Get the database connection foreign key constraints configuration option. - * - * @return bool|null - */ - protected function getForeignKeyConstraintsConfigurationValue() - { - return $this->getConfig('foreign_key_constraints'); - } + use \October\Rain\Database\Connections\ExtendsConnection; } diff --git a/src/Database/Connections/SqlServerConnection.php b/src/Database/Connections/SqlServerConnection.php index cc2dc2cb1..d1b7acd3d 100644 --- a/src/Database/Connections/SqlServerConnection.php +++ b/src/Database/Connections/SqlServerConnection.php @@ -1,121 +1,11 @@ getDriverName() === 'sqlsrv') { - return parent::transaction($callback); - } - - $this->getPdo()->exec('BEGIN TRAN'); - - // We'll simply execute the given callback within a try / catch block - // and if we catch any exception we can rollback the transaction - // so that none of the changes are persisted to the database. - try { - $result = $callback($this); - - $this->getPdo()->exec('COMMIT TRAN'); - } - - // If we catch an exception, we will rollback so nothing gets messed - // up in the database. Then we'll re-throw the exception so it can - // be handled how the developer sees fit for their applications. - catch (Throwable $e) { - $this->getPdo()->exec('ROLLBACK TRAN'); - - throw $e; - } - - return $result; - } - } - - /** - * Get the default query grammar instance. - * - * @return \Illuminate\Database\Query\Grammars\SqlServerGrammar - */ - protected function getDefaultQueryGrammar() - { - return $this->withTablePrefix(new QueryGrammar); - } - - /** - * Get a schema builder instance for the connection. - * - * @return \Illuminate\Database\Schema\SqlServerBuilder - */ - public function getSchemaBuilder() - { - if (is_null($this->schemaGrammar)) { - $this->useDefaultSchemaGrammar(); - } - - return new SqlServerBuilder($this); - } - - /** - * Get the default schema grammar instance. - * - * @return \Illuminate\Database\Schema\Grammars\SqlServerGrammar - */ - protected function getDefaultSchemaGrammar() - { - return $this->withTablePrefix(new SchemaGrammar); - } - - /** - * Get the schema state for the connection. - * - * @param \Illuminate\Filesystem\Filesystem|null $files - * @param callable|null $processFactory - * - * @throws \RuntimeException - */ - public function getSchemaState(Filesystem $files = null, callable $processFactory = null) - { - throw new RuntimeException('Schema dumping is not supported when using SQL Server.'); - } - - /** - * Get the default post processor instance. - * - * @return \Illuminate\Database\Query\Processors\SqlServerProcessor - */ - protected function getDefaultPostProcessor() - { - return new SqlServerProcessor; - } - - /** - * Get the Doctrine DBAL driver. - * - * @return \Illuminate\Database\PDO\SqlServerDriver - */ - protected function getDoctrineDriver() - { - return new SqlServerDriver; - } + use \October\Rain\Database\Connections\ExtendsConnection; }