Failed Conditions
Pull Request — 3.0.x (#3980)
by Guilherme
07:55
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 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
c 0
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
    public function lastInsertId($name = null)
20
    {
21
        if ($name === null) {
22
            return parent::lastInsertId($name);
23
        }
24
25
        $stmt = $this->prepare('SELECT CONVERT(VARCHAR(MAX), current_value) FROM sys.sequences WHERE name = ?');
26
        $stmt->execute([$name]);
27
28
        return $stmt->fetchColumn();
29
    }
30
31
    /**
32
     * {@inheritDoc}
33
     */
34
    public function quote($value, $type = ParameterType::STRING)
35
    {
36
        $val = parent::quote($value, $type);
37
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
        return $val;
44
    }
45
46
    protected function createStatement(\PDOStatement $stmt) : PDOStatement
47
    {
48
        return new Statement($stmt);
49
    }
50
}
51