Failed Conditions
Pull Request — 2.10 (#3803)
by Sergei
62:38
created

Connection::createStatement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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