1
|
|
<?php
|
2
|
|
/**
|
3
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
4
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
5
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
6
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
7
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
8
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
9
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
10
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
11
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
12
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
13
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
14
|
|
*
|
15
|
|
* This software consists of voluntary contributions made by many individuals
|
16
|
|
* and is licensed under the LGPL. For more information please see
|
17
|
|
* <http://phing.info>.
|
18
|
|
*/
|
19
|
|
|
20
|
|
/**
|
21
|
|
* "Inner" class that contains the definition of a new transaction element.
|
22
|
|
* Transactions allow several files or blocks of statements
|
23
|
|
* to be executed using the same JDBC connection and commit
|
24
|
|
* operation in between.
|
25
|
|
*
|
26
|
|
* @package phing.tasks.ext.pdo
|
27
|
|
*/
|
28
|
|
class PDOSQLExecTransaction
|
29
|
|
{
|
30
|
|
private $tSrcFile = null;
|
31
|
|
private $tSqlCommand = "";
|
32
|
|
private $parent;
|
33
|
|
|
34
|
|
/**
|
35
|
|
* @param $parent
|
36
|
|
*/
|
37
|
1
|
public function __construct($parent)
|
38
|
|
{
|
39
|
|
// Parent is required so that we can log things ...
|
40
|
1
|
$this->parent = $parent;
|
41
|
|
}
|
42
|
|
|
43
|
|
/**
|
44
|
|
* @param PhingFile $src
|
45
|
|
*/
|
46
|
1
|
public function setSrc(PhingFile $src)
|
47
|
|
{
|
48
|
1
|
$this->tSrcFile = $src;
|
49
|
|
}
|
50
|
|
|
51
|
|
/**
|
52
|
|
* @param $sql
|
53
|
|
*/
|
54
|
1
|
public function addText($sql)
|
55
|
|
{
|
56
|
1
|
$this->tSqlCommand .= $sql;
|
57
|
|
}
|
58
|
|
|
59
|
|
/**
|
60
|
|
* @throws IOException, PDOException
|
61
|
|
*/
|
62
|
1
|
public function runTransaction()
|
63
|
|
{
|
64
|
1
|
if (!empty($this->tSqlCommand)) {
|
65
|
0
|
$this->parent->log("Executing commands", Project::MSG_INFO);
|
66
|
0
|
$this->parent->runStatements(new StringReader($this->tSqlCommand));
|
67
|
|
}
|
68
|
|
|
69
|
1
|
if ($this->tSrcFile !== null) {
|
70
|
1
|
$this->parent->log(
|
71
|
1
|
"Executing file: " . $this->tSrcFile->getAbsolutePath(),
|
72
|
1
|
Project::MSG_INFO
|
73
|
|
);
|
74
|
1
|
$reader = new FileReader($this->tSrcFile);
|
75
|
1
|
$this->parent->runStatements($reader);
|
76
|
1
|
$reader->close();
|
77
|
|
}
|
78
|
|
}
|
79
|
|
}
|