Failed Conditions
Push — develop ( 55bd22...e46c09 )
by Sergei
33s queued 23s
created

Connection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
eloc 10
dl 0
loc 38
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A quote() 0 10 2
A createStatement() 0 3 1
A lastInsertId() 0 10 2
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