Failed Conditions
Pull Request — 2.10 (#3762)
by Benjamin
09:16
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 2
crap 6
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