Passed
Pull Request — master (#3759)
by Benjamin
65:19
created

Connection::getSequenceNumber()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0625

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 12
ccs 6
cts 8
cp 0.75
rs 10
cc 2
nc 2
nop 1
crap 2.0625
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