Passed
Push — exceptions ( 722472 )
by Michael
15:25
created

Connection::createStatement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.037

Importance

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