Failed Conditions
Pull Request — develop (#3368)
by Benjamin
42:38 queued 39:25
created

Connection::getSequenceNumber()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2.0438

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 12
ccs 7
cts 9
cp 0.7778
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.0438
1
<?php
2
3
namespace Doctrine\DBAL\Driver\PDOSqlsrv;
4
5
use Doctrine\DBAL\Driver\DriverException;
6
use Doctrine\DBAL\Driver\PDOConnection;
7
use Doctrine\DBAL\Driver\PDOStatement;
8
use function strpos;
9
use function substr;
10
11
/**
12
 * Sqlsrv Connection implementation.
13
 */
14
class Connection extends PDOConnection implements \Doctrine\DBAL\Driver\Connection
15
{
16
    /**
17
     * {@inheritDoc}
18
     */
19 2
    public function getSequenceNumber(string $name) : string
20
    {
21 2
        $stmt = $this->prepare('SELECT CONVERT(VARCHAR(MAX), current_value) FROM sys.sequences WHERE name = ?');
22 2
        $stmt->execute([$name]);
23
24 2
        $result = $stmt->fetchColumn();
25
26 2
        if ($result === false) {
27 1
            throw DriverException::noSuchSequence($name);
28
        }
29
30 1
        return (string) $result;
31
    }
32
33
    /**
34
     * {@inheritDoc}
35
     */
36 7
    public function quote(string $value) : string
37
    {
38 7
        $val = parent::quote($value);
39
40
        // Fix for a driver version terminating all values with null byte
41 7
        if (strpos($val, "\0") !== false) {
42
            $val = substr($val, 0, -1);
43
        }
44
45 7
        return $val;
46
    }
47
48
    /**
49
     * {@inheritDoc}
50
     */
51 246
    protected function createStatement(\PDOStatement $stmt) : PDOStatement
52
    {
53 246
        return new Statement($stmt);
54
    }
55
}
56