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\Util\StringHelper; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Dummy query splitter: converts entire input into single |
27
|
|
|
* SQL string. |
28
|
|
|
* |
29
|
|
|
* @author Michiel Rook <[email protected]> |
30
|
|
|
*/ |
31
|
|
|
class DummyPDOQuerySplitter extends PDOQuerySplitter |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* Returns entire SQL source. |
35
|
|
|
* |
36
|
|
|
* @return null|string |
37
|
|
|
*/ |
38
|
9 |
|
public function nextQuery(): ?string |
39
|
|
|
{ |
40
|
9 |
|
$sql = null; |
41
|
|
|
|
42
|
9 |
|
while (($line = $this->sqlReader->readLine()) !== null) { |
43
|
9 |
|
$delimiter = $this->parent->getDelimiter(); |
44
|
9 |
|
$project = $this->parent->getOwningTarget()->getProject(); |
45
|
9 |
|
if (!$this->keepformat) { |
46
|
9 |
|
$line = trim($line); |
47
|
|
|
} |
48
|
9 |
|
if ($this->expandProperties) { |
49
|
9 |
|
$line = $project->replaceProperties($line); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
if ( |
53
|
9 |
|
!$this->keepformat |
54
|
9 |
|
&& ($line !== $delimiter) |
55
|
9 |
|
&& (StringHelper::startsWith('//', $line) |
56
|
9 |
|
|| StringHelper::startsWith('--', $line) |
57
|
9 |
|
|| StringHelper::startsWith('#', $line)) |
58
|
|
|
) { |
59
|
|
|
continue; |
60
|
|
|
} |
61
|
|
|
|
62
|
9 |
|
$sql .= ' ' . $line . "\n"; |
63
|
|
|
|
64
|
|
|
// SQL defines "--" as a comment to EOL |
65
|
|
|
// and in Oracle it may contain a hint |
66
|
|
|
// so we cannot just remove it, instead we must end it |
67
|
9 |
|
if (!$this->keepformat && strpos($line, '--') !== false) { |
68
|
|
|
$sql .= "\n"; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/* |
72
|
|
|
* fix issue with PDO and wrong formatted multi statements |
73
|
|
|
* |
74
|
|
|
* @issue 1108 |
75
|
|
|
*/ |
76
|
9 |
|
if (StringHelper::endsWith($delimiter, $line)) { |
77
|
3 |
|
break; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
9 |
|
return $sql; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|