| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace Doctrine\DBAL\Driver\PDO\SQLSrv;
|
|
|
4 |
|
|
|
5 |
use Doctrine\DBAL\Driver\Middleware\AbstractConnectionMiddleware;
|
|
|
6 |
use Doctrine\DBAL\Driver\PDO\Connection as PDOConnection;
|
|
|
7 |
use Doctrine\DBAL\Driver\Statement as StatementInterface;
|
|
|
8 |
use Doctrine\Deprecations\Deprecation;
|
|
|
9 |
use PDO;
|
|
|
10 |
|
|
|
11 |
final class Connection extends AbstractConnectionMiddleware
|
|
|
12 |
{
|
|
|
13 |
private PDOConnection $connection;
|
|
|
14 |
|
|
|
15 |
public function __construct(PDOConnection $connection)
|
|
|
16 |
{
|
|
|
17 |
parent::__construct($connection);
|
|
|
18 |
|
|
|
19 |
$this->connection = $connection;
|
|
|
20 |
}
|
|
|
21 |
|
|
|
22 |
public function prepare(string $sql): StatementInterface
|
|
|
23 |
{
|
|
|
24 |
return new Statement(
|
|
|
25 |
$this->connection->prepare($sql),
|
|
|
26 |
);
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* {@inheritDoc}
|
|
|
31 |
*/
|
|
|
32 |
public function lastInsertId($name = null)
|
|
|
33 |
{
|
|
|
34 |
if ($name === null) {
|
|
|
35 |
return parent::lastInsertId($name);
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
Deprecation::triggerIfCalledFromOutside(
|
|
|
39 |
'doctrine/dbal',
|
|
|
40 |
'https://github.com/doctrine/dbal/issues/4687',
|
|
|
41 |
'The usage of Connection::lastInsertId() with a sequence name is deprecated.',
|
|
|
42 |
);
|
|
|
43 |
|
|
|
44 |
$statement = $this->prepare(
|
|
|
45 |
'SELECT CONVERT(VARCHAR(MAX), current_value) FROM sys.sequences WHERE name = ?',
|
|
|
46 |
);
|
|
|
47 |
$statement->bindValue(1, $name);
|
|
|
48 |
|
|
|
49 |
return $statement->execute()
|
|
|
50 |
->fetchOne();
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
public function getNativeConnection(): PDO
|
|
|
54 |
{
|
|
|
55 |
return $this->connection->getNativeConnection();
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
/** @deprecated Call {@see getNativeConnection()} instead. */
|
|
|
59 |
public function getWrappedConnection(): PDO
|
|
|
60 |
{
|
|
|
61 |
Deprecation::trigger(
|
|
|
62 |
'doctrine/dbal',
|
|
|
63 |
'https://github.com/doctrine/dbal/pull/5037',
|
|
|
64 |
'%s is deprecated, call getNativeConnection() instead.',
|
|
|
65 |
__METHOD__,
|
|
|
66 |
);
|
|
|
67 |
|
|
|
68 |
return $this->connection->getWrappedConnection();
|
|
|
69 |
}
|
|
|
70 |
}
|