Failed Conditions
Pull Request — 2.10 (#3762)
by Benjamin
09:16
created

Connection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
eloc 11
dl 0
loc 39
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A quote() 0 10 2
A lastInsertId() 0 10 2
1
<?php
2
3
namespace Doctrine\DBAL\Driver\PDOSqlsrv;
4
5
use Doctrine\DBAL\Driver\PDOConnection;
6
use Doctrine\DBAL\ParameterType;
7
use PDO;
8
use function strpos;
9
use function substr;
10
11
/**
12
 * Sqlsrv Connection implementation.
13
 */
14
class Connection extends PDOConnection
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function __construct($dsn, $user = null, $password = null, ?array $options = null)
20
    {
21
        parent::__construct($dsn, $user, $password, $options);
22
        $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, [Statement::class, []]);
23
    }
24
25
    /**
26
     * {@inheritDoc}
27
     */
28
    public function lastInsertId($name = null)
29
    {
30
        if ($name === null) {
31
            return parent::lastInsertId($name);
32
        }
33
34
        $stmt = $this->prepare('SELECT CONVERT(VARCHAR(MAX), current_value) FROM sys.sequences WHERE name = ?');
35
        $stmt->execute([$name]);
36
37
        return $stmt->fetchColumn();
38
    }
39
40
    /**
41
     * {@inheritDoc}
42
     */
43
    public function quote($value, $type = ParameterType::STRING)
44
    {
45
        $val = parent::quote($value, $type);
46
47
        // Fix for a driver version terminating all values with null byte
48
        if (strpos($val, "\0") !== false) {
49
            $val = substr($val, 0, -1);
50
        }
51
52
        return $val;
53
    }
54
}
55