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
|
|
|
namespace Phing\Task\System\Pdo; |
21
|
|
|
|
22
|
|
|
use Phing\Io\File; |
23
|
|
|
use Phing\Util\StringHelper; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Plain text formatter for PDO results. |
27
|
|
|
* |
28
|
|
|
* @author Hans Lellelid <[email protected]> |
29
|
|
|
* @package phing.tasks.ext.pdo |
30
|
|
|
* @since 2.3.0 |
31
|
|
|
*/ |
32
|
|
|
class PlainPDOResultFormatter extends PDOResultFormatter |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* Have column headers been printed? |
36
|
|
|
* |
37
|
|
|
* @var boolean |
38
|
|
|
*/ |
39
|
|
|
private $colsprinted = false; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Whether to show headers. |
43
|
|
|
* |
44
|
|
|
* @var boolean |
45
|
|
|
*/ |
46
|
|
|
private $showheaders = true; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Column delimiter. |
50
|
|
|
* Defaults to ',' |
51
|
|
|
* |
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
private $coldelimiter = ","; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Row delimiter. |
58
|
|
|
* Defaults to PHP_EOL. |
59
|
|
|
* |
60
|
|
|
* @var string |
61
|
|
|
*/ |
62
|
|
|
private $rowdelimiter = PHP_EOL; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Set the showheaders attribute. |
66
|
|
|
* |
67
|
|
|
* @param boolean $v |
68
|
|
|
*/ |
69
|
|
|
public function setShowheaders($v) |
70
|
|
|
{ |
71
|
|
|
$this->showheaders = StringHelper::booleanValue($v); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Sets the column delimiter. |
76
|
|
|
* |
77
|
|
|
* @param string $v |
78
|
|
|
*/ |
79
|
|
|
public function setColdelim($v) |
80
|
|
|
{ |
81
|
|
|
$this->coldelimiter = $v; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Sets the row delimiter. |
86
|
|
|
* |
87
|
|
|
* @param string $v |
88
|
|
|
*/ |
89
|
|
|
public function setRowdelim($v) |
90
|
|
|
{ |
91
|
|
|
$this->rowdelimiter = $v; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Processes a specific row from PDO result set. |
96
|
|
|
* |
97
|
|
|
* @param array $row Row of PDO result set. |
98
|
|
|
*/ |
99
|
|
|
public function processRow($row) |
100
|
|
|
{ |
101
|
|
|
$line = ""; |
102
|
|
|
|
103
|
|
|
if (!$this->colsprinted && $this->showheaders) { |
104
|
|
|
$first = true; |
105
|
|
|
foreach ($row as $fieldName => $ignore) { |
106
|
|
|
if ($first) { |
107
|
|
|
$first = false; |
108
|
|
|
} else { |
109
|
|
|
$line .= ","; |
110
|
|
|
} |
111
|
|
|
$line .= $fieldName; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
$this->out->write($line); |
115
|
|
|
$this->out->write(PHP_EOL); |
116
|
|
|
|
117
|
|
|
$line = ""; |
118
|
|
|
$colsprinted = true; |
|
|
|
|
119
|
|
|
} // if show headers |
120
|
|
|
|
121
|
|
|
$first = true; |
122
|
|
|
foreach ($row as $columnValue) { |
123
|
|
|
if ($columnValue != null) { |
124
|
|
|
$columnValue = trim($columnValue); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
if ($first) { |
128
|
|
|
$first = false; |
129
|
|
|
} else { |
130
|
|
|
$line .= $this->coldelimiter; |
131
|
|
|
} |
132
|
|
|
$line .= $columnValue; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
$this->out->write($line); |
136
|
|
|
$this->out->write($this->rowdelimiter); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @return File |
141
|
|
|
*/ |
142
|
|
|
public function getPreferredOutfile() |
143
|
|
|
{ |
144
|
|
|
return new File('results.txt'); |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|