Failed Conditions
Push — exceptions ( 64d080...7fc4df )
by Michael
15:07
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
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
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
    public function lastInsertId($name = null)
22
    {
23
        if (null === $name) {
24
            return parent::lastInsertId($name);
25
        }
26
27
        $stmt = $this->prepare('SELECT CONVERT(VARCHAR(MAX), current_value) FROM sys.sequences WHERE name = ?');
28
        $stmt->execute([$name]);
29
30
        return $stmt->fetchColumn();
31
    }
32
33
    /**
34
     * {@inheritDoc}
35
     */
36
    public function quote($value, $type = ParameterType::STRING)
37
    {
38
        $val = parent::quote($value, $type);
39
40
        // Fix for a driver version terminating all values with null byte
41
        if (strpos($val, "\0") !== false) {
42
            $val = substr($val, 0, -1);
43
        }
44
45
        return $val;
46
    }
47
48
    /**
49
     * {@inheritDoc}
50
     */
51
    protected function createStatement(\PDOStatement $stmt) : PDOStatement
52
    {
53
        return new Statement($stmt);
54
    }
55
}
56