|
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
|
354 |
|
protected function initConnection() |
|
73
|
|
|
{ |
|
74
|
354 |
|
parent::initConnection(); |
|
75
|
|
|
|
|
76
|
354 |
|
if($this->isISeries === null){ |
|
77
|
|
|
try { |
|
78
|
354 |
|
$stmt = $this->pdo->query('SELECT * FROM QSYS2.SYSTABLES FETCH FIRST 1 ROW ONLY'); |
|
79
|
|
|
$this->isISeries = boolval($stmt); |
|
80
|
354 |
|
} catch (\Exception $ex) { |
|
81
|
354 |
|
$this->isISeries = false; |
|
82
|
|
|
} |
|
83
|
354 |
|
} |
|
84
|
|
|
|
|
85
|
354 |
|
if($this->defaultSchema && !$this->isISeries){ |
|
86
|
352 |
|
$this->pdo->exec('SET CURRENT SCHEMA ' . $this->pdo->quote($this->defaultSchema)); |
|
87
|
352 |
|
} |
|
88
|
|
|
|
|
89
|
354 |
|
} |
|
90
|
|
|
|
|
91
|
|
|
} |
|
92
|
|
|
|