-
Notifications
You must be signed in to change notification settings - Fork 414
/
Copy pathMssqlPropelPDO.php
159 lines (144 loc) · 4.23 KB
/
MssqlPropelPDO.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
/**
* dblib doesn't support transactions so we need to add a workaround for transactions, last insert ID, and quoting
*
* @package propel.runtime.adapter.MSSQL
*/
class MssqlPropelPDO extends PropelPDO
{
/**
* Begin a transaction.
*
* It is necessary to override the abstract PDO transaction functions here, as
* the PDO driver for MSSQL does not support transactions.
*
* @return integer
*/
public function beginTransaction()
{
$return = true;
$opcount = $this->getNestedTransactionCount();
if ($opcount === 0) {
$return = self::exec('BEGIN TRANSACTION');
if ($this->useDebug) {
$this->log('Begin transaction', null, __METHOD__);
}
$this->isUncommitable = false;
}
$this->nestedTransactionCount++;
return $return;
}
/**
* Commit a transaction.
*
* It is necessary to override the abstract PDO transaction functions here, as
* the PDO driver for MSSQL does not support transactions.
*
* @return integer
*
* @throws PropelException
*/
public function commit()
{
$return = true;
$opcount = $this->getNestedTransactionCount();
if ($opcount > 0) {
if ($opcount === 1) {
if ($this->isUncommitable) {
throw new PropelException('Cannot commit because a nested transaction was rolled back');
} else {
$return = self::exec('COMMIT TRANSACTION');
if ($this->useDebug) {
$this->log('Commit transaction', null, __METHOD__);
}
}
}
$this->nestedTransactionCount--;
}
return $return;
}
/**
* Roll-back a transaction.
*
* It is necessary to override the abstract PDO transaction functions here, as
* the PDO driver for MSSQL does not support transactions.
*
* @return integer
*/
public function rollBack()
{
$return = true;
$opcount = $this->getNestedTransactionCount();
if ($opcount > 0) {
if ($opcount === 1) {
$return = self::exec('ROLLBACK TRANSACTION');
if ($this->useDebug) {
$this->log('Rollback transaction', null, __METHOD__);
}
} else {
$this->isUncommitable = true;
}
$this->nestedTransactionCount--;
}
return $return;
}
/**
* Rollback the whole transaction, even if this is a nested rollback
* and reset the nested transaction count to 0.
*
* It is necessary to override the abstract PDO transaction functions here, as
* the PDO driver for MSSQL does not support transactions.
*
* @return integer
*/
public function forceRollBack()
{
$return = true;
$opcount = $this->getNestedTransactionCount();
if ($opcount > 0) {
// If we're in a transaction, always roll it back
// regardless of nesting level.
$return = self::exec('ROLLBACK TRANSACTION');
// reset nested transaction count to 0 so that we don't
// try to commit (or rollback) the transaction outside this scope.
$this->nestedTransactionCount = 0;
if ($this->useDebug) {
$this->log('Rollback transaction', null, __METHOD__);
}
}
return $return;
}
/**
* @param string $seqname
*
* @return integer
*/
public function lastInsertId($seqname = null)
{
$result = self::query('SELECT SCOPE_IDENTITY()');
return (int) $result->fetchColumn();
}
/**
* @param string $text
*
* @return string
*/
public function quoteIdentifier($text)
{
return '[' . $text . ']';
}
/**
* @return boolean
*/
public function useQuoteIdentifier()
{
return true;
}
}