chiark / gitweb /
Choose columns for routetrade
[ypp-sc-tools.main.git] / yarrg / web / dumpqueryresults
1 <%doc>
2
3  This is part of the YARRG website.  YARRG is a tool and website
4  for assisting players of Yohoho Puzzle Pirates.
5
6  Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
7  Copyright (C) 2009 Clare Boothby
8
9   YARRG's client code etc. is covered by the ordinary GNU GPL (v3 or later).
10   The YARRG website is covered by the GNU Affero GPL v3 or later, which
11    basically means that every installation of the website will let you
12    download the source.
13
14  This program is free software: you can redistribute it and/or modify
15  it under the terms of the GNU Affero General Public License as
16  published by the Free Software Foundation, either version 3 of the
17  License, or (at your option) any later version.
18
19  This program is distributed in the hope that it will be useful,
20  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  GNU Affero General Public License for more details.
23
24  You should have received a copy of the GNU Affero General Public License
25  along with this program.  If not, see <http://www.gnu.org/licenses/>.
26
27  Yohoho and Puzzle Pirates are probably trademarks of Three Rings and
28  are used without permission.  This program is not endorsed or
29  sponsored by Three Rings.
30
31
32  This Mason component is helpful for debugging and developing.  It
33  outputs SQL query results as HTML tables.  You can either:
34     <& dumpqueryresults, sth = $executed_statement_handle &>
35  in which case it will consume the results of the statement and
36  print them unconditionally, or do the equivalent of:
37     <& dumpqueryresults:start, sth => $sth, [ qa => $qa ] &>
38     %   my $row;
39     %   while ($row= $sth->fetchrow_hashref) {
40     <& dumpqueryresults:row, sth => $sth, row => $row, [ qa => $qa ] &>
41     %       do something else with $row
42     %   }
43     <& dumpqueryresults:end, [ qa => $qa ] &>
44  where if you pass $qa, dumpqueryresults will check whether debug
45  is enabled and produce no output if it isn't.  NB you don't want
46  this approach if your loop body produces output because it'll be
47  interleaved with dumpqueryresults' table.
48
49 </%doc>
50 <%args>
51 $sth
52 </%args>
53
54 <%method start>
55 <%args>
56 $sth
57 $qa => undef
58 </%args>
59 %       if (!$qa || $qa->{'debug'}) {
60 <table frame=box rules=all>
61 <tr>
62 %               foreach my $field (@{ $sth->{NAME} }) {
63 <th><% $field |h %>
64 %               }
65 </tr>
66 %       }
67 </%method>
68
69 <%method row>
70 <%args>
71 $sth
72 $row
73 $qa => undef
74 </%args>
75 %       if (!$qa || $qa->{'debug'}) {
76 <tr>
77 %               foreach my $field (@{ $sth->{NAME} }) {
78 %                       my $cell= $row->{$field};
79 <td>
80 <% $cell |h %>
81 </td>
82 %               }
83 </tr>
84 %       }
85 </%method>
86
87 <%method end>
88 <%args>
89 $qa => undef
90 </%args>
91 %       if (!$qa || $qa->{'debug'}) {
92 </table>
93 %       }
94 </%method>
95
96 <& SELF:start, sth => $sth &>
97 %       my $row;
98 %       while ($row= $sth->fetchrow_hashref) {
99 <& SELF:row, sth => $sth, row => $row &>
100 %       }
101 <& SELF:end &>