Failed Conditions
Pull Request — develop (#3525)
by Jonathan
12:46
created

Connection::quote()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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