|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @link http://www.yiiframework.com/ |
|
4
|
|
|
* @copyright Copyright (c) 2008 Yii Software LLC |
|
5
|
|
|
* @license http://www.yiiframework.com/license/ |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace edgardmessias\db\firebird; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* |
|
12
|
|
|
* @author Edgard Lorraine Messias <[email protected]> |
|
13
|
|
|
* @since 2.0 |
|
14
|
|
|
*/ |
|
15
|
|
|
class Connection extends \yii\db\Connection |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* Firebird server version |
|
19
|
|
|
*/ |
|
20
|
|
|
public $firebird_version = null; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @inheritdoc |
|
24
|
|
|
*/ |
|
25
|
|
|
public $schemaMap = [ |
|
26
|
|
|
'firebird' => 'edgardmessias\db\firebird\Schema', // Firebird |
|
27
|
|
|
]; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @inheritdoc |
|
31
|
|
|
*/ |
|
32
|
|
|
public $pdoClass = 'edgardmessias\db\firebird\PdoAdapter'; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @inheritdoc |
|
36
|
|
|
*/ |
|
37
|
|
|
public $commandClass = 'edgardmessias\db\firebird\Command'; |
|
38
|
|
|
/** |
|
39
|
|
|
* @var Transaction the currently active transaction |
|
40
|
|
|
*/ |
|
41
|
|
|
private $_transaction; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Returns the currently active transaction. |
|
45
|
|
|
* @return Transaction the currently active transaction. Null if no active transaction. |
|
46
|
|
|
*/ |
|
47
|
138 |
|
public function getTransaction() |
|
48
|
|
|
{ |
|
49
|
138 |
|
return $this->_transaction && $this->_transaction->getIsActive() ? $this->_transaction : null; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Starts a transaction. |
|
54
|
|
|
* @param string|null $isolationLevel The isolation level to use for this transaction. |
|
55
|
|
|
* See [[Transaction::begin()]] for details. |
|
56
|
|
|
* @return Transaction the transaction initiated |
|
57
|
|
|
*/ |
|
58
|
6 |
|
public function beginTransaction($isolationLevel = null) |
|
59
|
|
|
{ |
|
60
|
6 |
|
$this->open(); |
|
61
|
|
|
|
|
62
|
6 |
|
if (($transaction = $this->getTransaction()) === null) { |
|
63
|
6 |
|
$transaction = $this->_transaction = new Transaction(['db' => $this]); |
|
64
|
|
|
} |
|
65
|
6 |
|
$transaction->begin($isolationLevel); |
|
66
|
|
|
|
|
67
|
6 |
|
return $transaction; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
263 |
|
public function close() |
|
71
|
|
|
{ |
|
72
|
263 |
|
if ($this->pdo !== null) { |
|
73
|
160 |
|
$this->_transaction = null; |
|
74
|
|
|
} |
|
75
|
263 |
|
parent::close(); |
|
76
|
263 |
|
} |
|
77
|
|
|
|
|
78
|
160 |
|
public function init() |
|
79
|
|
|
{ |
|
80
|
160 |
|
parent::init(); |
|
81
|
|
|
|
|
82
|
160 |
|
if ($this->firebird_version) { |
|
83
|
148 |
|
return; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
160 |
|
try { |
|
87
|
|
|
$pdo = $this->createPdoInstance(); |
|
88
|
160 |
|
|
|
89
|
160 |
|
$server_version = $pdo->getAttribute(\PDO::ATTR_SERVER_VERSION); |
|
90
|
|
|
|
|
91
|
160 |
|
if (preg_match('/\w{2}-[TV](\d+\.\d+\.\d+).*remote server/', $server_version, $matches)) { |
|
92
|
|
|
$this->firebird_version = $matches[1]; |
|
93
|
|
|
} |
|
94
|
|
|
} catch (\Exception $ex) { |
|
|
|
|
|
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Reset the connection after cloning. |
|
100
|
|
|
*/ |
|
101
|
|
|
public function __clone() |
|
102
|
|
|
{ |
|
103
|
|
|
parent::__clone(); |
|
104
|
|
|
|
|
105
|
|
|
$this->_transaction = null; |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|