Skip to content

Commit

Permalink
Merge pull request #5038 from derrabus/improvement/sqlsrv-as-middleware
Browse files Browse the repository at this point in the history
Use abstract middleware classes for PDO_sqlsrv
  • Loading branch information
morozov authored Nov 27, 2021
2 parents 906dc83 + d784f93 commit 59f914f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 57 deletions.
51 changes: 5 additions & 46 deletions src/Driver/PDO/SQLSrv/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

namespace Doctrine\DBAL\Driver\PDO\SQLSrv;

use Doctrine\DBAL\Driver\Middleware\AbstractConnectionMiddleware;
use Doctrine\DBAL\Driver\PDO\Connection as PDOConnection;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\Driver\Statement as StatementInterface;
use Doctrine\DBAL\ParameterType;
use Doctrine\Deprecations\Deprecation;
use PDO;

final class Connection implements ServerInfoAwareConnection
final class Connection extends AbstractConnectionMiddleware
{
/** @var PDOConnection */
private $connection;

public function __construct(PDOConnection $connection)
{
parent::__construct($connection);

$this->connection = $connection;
}

Expand All @@ -27,31 +27,13 @@ public function prepare(string $sql): StatementInterface
);
}

public function query(string $sql): Result
{
return $this->connection->query($sql);
}

/**
* {@inheritDoc}
*/
public function quote($value, $type = ParameterType::STRING)
{
return $this->connection->quote($value, $type);
}

public function exec(string $sql): int
{
return $this->connection->exec($sql);
}

/**
* {@inheritDoc}
*/
public function lastInsertId($name = null)
{
if ($name === null) {
return $this->connection->lastInsertId($name);
return parent::lastInsertId($name);
}

Deprecation::triggerIfCalledFromOutside(
Expand All @@ -65,29 +47,6 @@ public function lastInsertId($name = null)
->fetchOne();
}

public function beginTransaction(): bool
{
return $this->connection->beginTransaction();
}

public function commit(): bool
{
return $this->connection->commit();
}

public function rollBack(): bool
{
return $this->connection->rollBack();
}

/**
* {@inheritDoc}
*/
public function getServerVersion()
{
return $this->connection->getServerVersion();
}

public function getNativeConnection(): PDO
{
return $this->connection->getNativeConnection();
Expand Down
15 changes: 4 additions & 11 deletions src/Driver/PDO/SQLSrv/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

namespace Doctrine\DBAL\Driver\PDO\SQLSrv;

use Doctrine\DBAL\Driver\Middleware\AbstractStatementMiddleware;
use Doctrine\DBAL\Driver\PDO\Statement as PDOStatement;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Driver\Statement as StatementInterface;
use Doctrine\DBAL\ParameterType;
use Doctrine\Deprecations\Deprecation;
use PDO;

use function func_num_args;

final class Statement implements StatementInterface
final class Statement extends AbstractStatementMiddleware
{
/** @var PDOStatement */
private $statement;
Expand All @@ -21,6 +20,8 @@ final class Statement implements StatementInterface
*/
public function __construct(PDOStatement $statement)
{
parent::__construct($statement);

$this->statement = $statement;
}

Expand Down Expand Up @@ -74,12 +75,4 @@ public function bindValue($param, $value, $type = ParameterType::STRING): bool
{
return $this->bindParam($param, $value, $type);
}

/**
* {@inheritdoc}
*/
public function execute($params = null): Result
{
return $this->statement->execute($params);
}
}

0 comments on commit 59f914f

Please sign in to comment.