Completed
Push — master ( c7757e...39cb21 )
by Luís
16s
created

lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php (1 issue)

1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace Doctrine\DBAL\Driver\PDOSqlsrv;
21
22
use Doctrine\DBAL\Driver\PDOConnection;
23
24
/**
25
 * Sqlsrv Connection implementation.
26
 *
27
 * @since 2.0
28
 */
29
class Connection extends PDOConnection implements \Doctrine\DBAL\Driver\Connection
30
{
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function __construct($dsn, $user = null, $password = null, array $options = null)
35
    {
36
        parent::__construct($dsn, $user, $password, $options);
37
        $this->setAttribute(\PDO::ATTR_STATEMENT_CLASS, [Statement::class, []]);
38
    }
39
40
    /**
41
     * {@inheritDoc}
42
     */
43 View Code Duplication
    public function lastInsertId($name = null)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
    {
45
        if (null === $name) {
46
            return parent::lastInsertId($name);
47
        }
48
49
        $stmt = $this->prepare('SELECT CONVERT(VARCHAR(MAX), current_value) FROM sys.sequences WHERE name = ?');
50
        $stmt->execute([$name]);
51
52
        return $stmt->fetchColumn();
53
    }
54
55
    /**
56
     * {@inheritDoc}
57
     */
58
    public function quote($value, $type=\PDO::PARAM_STR)
59
    {
60
        $val = parent::quote($value, $type);
61
62
        // Fix for a driver version terminating all values with null byte
63
        if (strpos($val, "\0") !== false) {
64
            $val = substr($val, 0, -1);
65
        }
66
67
        return $val;
68
    }
69
}
70