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