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