Completed
Push — master ( e258ca...1fbbc1 )
by Edgard
02:39
created

Connection::initConnection()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 2
Metric Value
c 3
b 0
f 2
dl 0
loc 17
rs 9.2
cc 4
eloc 10
nc 8
nop 0
1
<?php
2
3
/**
4
 * @link http://www.yiiframework.com/
5
 * @copyright Copyright (c) 2008 Yii Software LLC
6
 * @license http://www.yiiframework.com/license/
7
 */
8
9
namespace edgardmessias\db\ibm\db2;
10
11
use PDO;
12
13
/**
14
 * @author Edgard Messias <[email protected]>
15
 * @since 1.0
16
 */
17
class Connection extends \yii\db\Connection
18
{
19
20
    /**
21
     * @inheritdoc
22
     */
23
    public $commandClass = 'edgardmessias\db\ibm\db2\Command';
24
25
    /**
26
     * @var bool|null set to true if working on iSeries
27
     */
28
29
    public $isISeries = null;
30
31
32
    /**
33
     * @var string need to be set if isISeries is set to true
34
     */
35
36
    public $defaultSchema;
37
38
39
    /**
40
     * @var array PDO attributes (name => value) that should be set when calling [[open()]]
41
     * to establish a DB connection. Please refer to the
42
     * [PHP manual](http://www.php.net/manual/en/function.PDO-setAttribute.php) for
43
     * details about available attributes.
44
     */
45
    public $attributes = [
46
        PDO::ATTR_CASE => PDO::CASE_NATURAL,
47
        PDO::ATTR_STRINGIFY_FETCHES => true,
48
    ];
49
    
50
    /**
51
     * @var array mapping between PDO driver names and [[Schema]] classes.
52
     * The keys of the array are PDO driver names while the values the corresponding
53
     * schema class name or configuration. Please refer to [[Yii::createObject()]] for
54
     * details on how to specify a configuration.
55
     *
56
     * This property is mainly used by [[getSchema()]] when fetching the database schema information.
57
     * You normally do not need to set this property unless you want to use your own
58
     * [[Schema]] class to support DBMS that is not supported by Yii.
59
     */
60
    public $schemaMap = [
61
        'ibm'   => 'edgardmessias\db\ibm\db2\Schema', // IBM DB2
62
        'odbc'   => 'edgardmessias\db\ibm\db2\Schema', // IBM DB2 ODBC
63
    ];
64
    
65
    /**
66
     * Initializes the DB connection.
67
     * This method is invoked right after the DB connection is established.
68
     * The default implementation turns on `PDO::ATTR_EMULATE_PREPARES`
69
     * if [[emulatePrepare]] is true, and sets the database [[charset]] if it is not empty.
70
     * It then triggers an [[EVENT_AFTER_OPEN]] event.
71
     */
72
    protected function initConnection()
73
    {
74
        parent::initConnection();
75
76
        if($this->defaultSchema){
77
            $this->pdo->exec('SET CURRENT SCHEMA ' . $this->pdo->quote($this->defaultSchema));
78
        }
79
        
80
        if($this->isISeries === null){
81
            try {
82
                $stmt = $this->pdo->query('SELECT * FROM QSYS2.SYSTABLES FETCH FIRST 1 ROW ONLY');
83
                $this->isIseries = boolval($stmt);
0 ignored issues
show
Bug introduced by
The property isIseries does not seem to exist. Did you mean isISeries?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
84
            } catch (Exception $ex) {
0 ignored issues
show
Bug introduced by
The class edgardmessias\db\ibm\db2\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
85
                $this->isIseries = false;
0 ignored issues
show
Bug introduced by
The property isIseries does not seem to exist. Did you mean isISeries?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
86
            }
87
        }
88
    }
89
90
}
91