1 |
<?php
|
2 |
/*
|
3 |
* $Id: Mysql.php 2702 2007-10-03 21:43:22Z Jonathan.Wage $
|
4 |
*
|
5 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
6 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
7 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
8 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
9 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
10 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
11 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
12 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
13 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
14 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
15 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
16 |
*
|
17 |
* This software consists of voluntary contributions made by many individuals
|
18 |
* and is licensed under the LGPL. For more information, see
|
19 |
* <http://www.phpdoctrine.com>.
|
20 |
*/
|
21 |
Doctrine::autoload('Doctrine_Transaction');
|
22 |
/**
|
23 |
*
|
24 |
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
25 |
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
|
26 |
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
27 |
* @package Doctrine
|
28 |
* @subpackage Transaction
|
29 |
* @link www.phpdoctrine.com
|
30 |
* @since 1.0
|
31 |
* @version $Revision: 2702 $
|
32 |
*/
|
33 |
class Doctrine_Transaction_Mysql extends Doctrine_Transaction
|
34 |
{
|
35 |
/**
|
36 |
* createSavepoint
|
37 |
* creates a new savepoint
|
38 |
*
|
39 |
* @param string $savepoint name of a savepoint to set
|
40 |
* @return void
|
41 |
*/
|
42 |
protected function createSavePoint($savepoint)
|
43 |
{
|
44 |
$query = 'SAVEPOINT ' . $savepoint;
|
45 |
|
46 |
return $this->conn->execute($query);
|
47 |
}
|
48 |
/**
|
49 |
* releaseSavePoint
|
50 |
* releases given savepoint
|
51 |
*
|
52 |
* @param string $savepoint name of a savepoint to release
|
53 |
* @return void
|
54 |
*/
|
55 |
protected function releaseSavePoint($savepoint)
|
56 |
{
|
57 |
$query = 'RELEASE SAVEPOINT ' . $savepoint;
|
58 |
|
59 |
return $this->conn->execute($query);
|
60 |
}
|
61 |
/**
|
62 |
* rollbackSavePoint
|
63 |
* releases given savepoint
|
64 |
*
|
65 |
* @param string $savepoint name of a savepoint to rollback to
|
66 |
* @return void
|
67 |
*/
|
68 |
protected function rollbackSavePoint($savepoint)
|
69 |
{
|
70 |
$query = 'ROLLBACK TO SAVEPOINT ' . $savepoint;
|
71 |
|
72 |
return $this->conn->execute($query);
|
73 |
}
|
74 |
/**
|
75 |
* Set the transacton isolation level.
|
76 |
*
|
77 |
* @param string standard isolation level
|
78 |
* READ UNCOMMITTED (allows dirty reads)
|
79 |
* READ COMMITTED (prevents dirty reads)
|
80 |
* REPEATABLE READ (prevents nonrepeatable reads)
|
81 |
* SERIALIZABLE (prevents phantom reads)
|
82 |
*
|
83 |
* @throws Doctrine_Transaction_Exception if using unknown isolation level
|
84 |
* @throws PDOException if something fails at the PDO level
|
85 |
* @return void
|
86 |
*/
|
87 |
public function setIsolation($isolation)
|
88 |
{
|
89 |
switch ($isolation) {
|
90 |
case 'READ UNCOMMITTED':
|
91 |
case 'READ COMMITTED':
|
92 |
case 'REPEATABLE READ':
|
93 |
case 'SERIALIZABLE':
|
94 |
break;
|
95 |
default:
|
96 |
throw new Doctrine_Transaction_Exception('Isolation level ' . $isolation . ' is not supported.');
|
97 |
}
|
98 |
|
99 |
$query = 'SET SESSION TRANSACTION ISOLATION LEVEL ' . $isolation;
|
100 |
|
101 |
return $this->conn->execute($query);
|
102 |
}
|
103 |
/**
|
104 |
* getTransactionIsolation
|
105 |
*
|
106 |
* @return string returns the current session transaction isolation level
|
107 |
*/
|
108 |
public function getIsolation()
|
109 |
{
|
110 |
return $this->conn->fetchOne('SELECT @@tx_isolation');
|
111 |
}
|
112 |
} |