Passed
Pull Request — master (#17)
by Wilmer
12:43
created

MssqlConnection::isSybase()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Mssql\Connection;
6
7
use Yiisoft\Db\Connection\Connection;
8
use Yiisoft\Db\Command\Command;
9
use Yiisoft\Db\Mssql\Pdo\PDO;
10
use Yiisoft\Db\Mssql\Pdo\SqlsrvPDO;
11
use Yiisoft\Db\Mssql\Schema\MssqlSchema;
12
13
use function in_array;
14
15
/**
16
 * Database connection class prefilled for MSSQL Server.
17
 */
18
final class MssqlConnection extends Connection
19
{
20
    private bool $isSybase = false;
21
    private ?MssqlSchema $schema = null;
22
23
    public function createCommand($sql = null, $params = []): Command
24
    {
25
        if ($sql !== null) {
26
            $sql = $this->quoteSql($sql);
27
        }
28
29
        $command = new Command($this->getProfiler(), $this->getLogger(), $this, $sql);
0 ignored issues
show
Bug introduced by
The method getProfiler() does not exist on Yiisoft\Db\Mssql\Connection\MssqlConnection. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
        $command = new Command($this->/** @scrutinizer ignore-call */ getProfiler(), $this->getLogger(), $this, $sql);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method getLogger() does not exist on Yiisoft\Db\Mssql\Connection\MssqlConnection. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
        $command = new Command($this->getProfiler(), $this->/** @scrutinizer ignore-call */ getLogger(), $this, $sql);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
30
31
        return $command->bindValues($params);
32
    }
33
34
    /**
35
     * Returns the schema information for the database opened by this connection.
36
     *
37
     * @return MssqlSchema the schema information for the database opened by this connection.
38
     */
39
    public function getSchema(): MssqlSchema
40
    {
41
        if ($this->schema !== null) {
42
            return $this->schema;
43
        }
44
45
        return $this->schema = new MssqlSchema($this);
46
    }
47
48
    public function isSybase(): bool
49
    {
50
        return $this->isSybase;
51
    }
52
53
    /**
54
     * @param bool $value set the database connected via pdo_dblib is SyBase, for default it's false.
55
     */
56
    public function sybase(bool $value): void
57
    {
58
        $this->isSybase = $value;
59
    }
60
61
    protected function createPdoInstance(): \PDO
62
    {
63
        if ($this->getDriverName() === 'sqlsrv') {
64
            $pdo = new SqlsrvPDO($this->getDsn(), $this->getUsername(), $this->getPassword(), $this->getAttributes());
65
        } else {
66
            $pdo = new PDO($this->getDsn(), $this->getUsername(), $this->getPassword(), $this->getAttributes());
67
        }
68
69
        return $pdo;
70
    }
71
72
    protected function initConnection(): void
73
    {
74
        $this->getPDO()->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
75
76
        if (!$this->isSybase && in_array($this->getDriverName(), ['mssql', 'dblib'], true)) {
77
            $this->getPDO()->exec('SET ANSI_NULL_DFLT_ON ON');
78
        }
79
    }
80
}
81