Completed
Pull Request — master (#3759)
by Benjamin
61:16
created

Connection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 63.64%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 11
c 2
b 0
f 0
dl 0
loc 40
ccs 14
cts 22
cp 0.6364
rs 10

3 Methods

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