-
Notifications
You must be signed in to change notification settings - Fork 8
/
CFirebirdPdoAdapter.php
97 lines (89 loc) · 2.74 KB
/
CFirebirdPdoAdapter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
* CFirebirdPdo class file
*
* @author idle sign <[email protected]>
*/
/**
* This is an extension of default PDO class for Firebird driver only
* It provides some missing functionalities of pdo driver
*
* @author idle sign <[email protected]>
*/
class CFirebirdPdoAdapter extends PDO
{
private $inTransaction = false;
/**
* Do some basic setup for Firebird.
* o Force use of exceptions on error.
* o Force all metadata to lower case.
* Yii will behave in unpredicatable ways if
* metadata is not lowercase.
* o Ensure that table names are not prefixed to
* fieldnames when returning metadata.
* Finally call parent constructor.
*
*/
function __construct($dsn, $username, $password, $driver_options = array())
{
// Windows OS paths with backslashes should be changed
$dsn = str_replace("\\", "/", $dsn);
// apply error mode
$driver_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
// lower case column names in results are necessary for Yii ActiveRecord proper functioning
$driver_options[PDO::ATTR_CASE] = PDO::CASE_LOWER;
// ensure we only receive fieldname not tablename.fieldname.
$driver_options[PDO::ATTR_FETCH_TABLE_NAMES] = FALSE;
parent::__construct($dsn, $username, $password, $driver_options);
}
/**
* Initiates a transaction
* @return bool <b>TRUE</b> on success or <b>FALSE</b> on failure.
*/
public function beginTransaction()
{
$this->setAttribute(PDO::ATTR_AUTOCOMMIT, false);
$r = $this->exec("SET TRANSACTION");
$success = ($r !== false);
if ($success) {
$this->inTransaction = true;
}
return ($success);
}
/**
* Commits a transaction
* @return bool <b>TRUE</b> on success or <b>FALSE</b> on failure.
*/
public function commit()
{
$r = $this->exec("COMMIT");
$this->setAttribute(PDO::ATTR_AUTOCOMMIT, true);
$success = ($r !== false);
if ($success) {
$this->inTransaction = false;
}
return ($success);
}
/**
* Rolls back a transaction
* @return bool <b>TRUE</b> on success or <b>FALSE</b> on failure.
*/
public function rollBack()
{
$r = $this->exec("ROLLBACK");
$this->setAttribute(PDO::ATTR_AUTOCOMMIT, true);
$success = ($r !== false);
if ($success) {
$this->inTransaction = false;
}
return ($success);
}
/**
* Checks if inside a transaction
* @return bool <b>TRUE</b> if a transaction is currently active, and <b>FALSE</b> if not.
*/
public function inTransaction()
{
return $this->inTransaction;
}
}