chiark / gitweb /
Generalise dumpqueryresults and rename to dumptable
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 23 Aug 2009 10:41:31 +0000 (11:41 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 23 Aug 2009 10:41:31 +0000 (11:41 +0100)
yarrg/web/dumptable [moved from yarrg/web/dumpqueryresults with 79% similarity]
yarrg/web/profitable_trades
yarrg/web/routetrade

similarity index 79%
rename from yarrg/web/dumpqueryresults
rename to yarrg/web/dumptable
index 8860ace69fa285e7cbde63beb399c75dd7050c7f..20dc25f12ceb4ea7a77e51302e7ec9557b53e10a 100644 (file)
 
 
  This Mason component is helpful for debugging and developing.  It
 
 
  This Mason component is helpful for debugging and developing.  It
- outputs SQL query results as HTML tables.  You can either:
-    <& dumpqueryresults, sth = $executed_statement_handle &>
+ outputs plain HTML tables eg for SQL query results.  You can either:
+    <& dumptable, sth = $executed_statement_handle &>
  in which case it will consume the results of the statement and
  print them unconditionally, or do the equivalent of:
  in which case it will consume the results of the statement and
  print them unconditionally, or do the equivalent of:
-    <& dumpqueryresults:start, sth => $sth, [ qa => $qa ] &>
+    <& dumptable:start, sth => $sth,              [ qa => $qa ] &> or
+    <& dumptable:start, cols => [ 'column',... ], [ qa => $qa ] &>
     %  my $row;
     %  while ($row= $sth->fetchrow_hashref) {
     %  my $row;
     %  while ($row= $sth->fetchrow_hashref) {
-    <& dumpqueryresults:row, sth => $sth, row => $row, [ qa => $qa ] &>
+    <& dumptable:row, sth|cols => ..., row => $row, [ qa => $qa ] &>
     %       do something else with $row
     %  }
     %       do something else with $row
     %  }
-    <& dumpqueryresults:end, [ qa => $qa ] &>
- where if you pass $qa, dumpqueryresults will check whether debug
+    <& dumptable:end, [ qa => $qa ] &>
+ where if you pass $qa, dumptable will check whether debug
  is enabled and produce no output if it isn't.  NB you don't want
  this approach if your loop body produces output because it'll be
  is enabled and produce no output if it isn't.  NB you don't want
  this approach if your loop body produces output because it'll be
- interleaved with dumpqueryresults' table.
+ interleaved with dumptable's table.
 
 </%doc>
 <%args>
 
 </%doc>
 <%args>
@@ -53,13 +54,14 @@ $sth
 
 <%method start>
 <%args>
 
 <%method start>
 <%args>
-$sth
+$sth => undef
+$cols => $sth->{NAME}
 $qa => undef
 </%args>
 %      if (!$qa || $qa->{'debug'}) {
 <table frame=box rules=all>
 <tr>
 $qa => undef
 </%args>
 %      if (!$qa || $qa->{'debug'}) {
 <table frame=box rules=all>
 <tr>
-%              foreach my $field (@{ $sth->{NAME} }) {
+%              foreach my $field (@$cols) {
 <th><% $field |h %>
 %              }
 </tr>
 <th><% $field |h %>
 %              }
 </tr>
@@ -68,13 +70,14 @@ $qa => undef
 
 <%method row>
 <%args>
 
 <%method row>
 <%args>
-$sth
+$sth => undef
+$cols => $sth->{NAME}
 $row
 $qa => undef
 </%args>
 %      if (!$qa || $qa->{'debug'}) {
 <tr>
 $row
 $qa => undef
 </%args>
 %      if (!$qa || $qa->{'debug'}) {
 <tr>
-%              foreach my $field (@{ $sth->{NAME} }) {
+%              foreach my $field (@$cols) {
 %                      my $cell= $row->{$field};
 <td>
 <% $cell |h %>
 %                      my $cell= $row->{$field};
 <td>
 <% $cell |h %>
index 1566baf1dd25c6dcc9fee8a4f0ef822fab664d3f..313a04ae6928165711ebe8034ad8d1a3c376b74c 100644 (file)
@@ -23,7 +23,7 @@ my $sth=$dbh->prepare(
 
 $sth->execute();
 </%perl>
 
 $sth->execute();
 </%perl>
-<& dumpqueryresults, sth => $sth &>
+<& dumptable, sth => $sth &>
 
 </BODY>
 </HTML>
 
 </BODY>
 </HTML>
index f8e0f89145b11888878067f383a74f5e9c1872fd..fa29e6a596936a933917d21368d28e52c069cabb 100644 (file)
@@ -143,15 +143,15 @@ my @columns= qw(org_name dst_name commodname
 % }
 
 % {
 % }
 
 % {
-<& dumpqueryresults:start, sth => $sth &>
+<& dumptable:start, sth => $sth &>
 %   my $flow;
 %   while ($flow= $sth->fetchrow_hashref()) {
 %      $flow->{Ix}= @flows;
 %      $flow->{Var}= "f$flow->{Ix}";
 %      push @flows, $flow;
 %   my $flow;
 %   while ($flow= $sth->fetchrow_hashref()) {
 %      $flow->{Ix}= @flows;
 %      $flow->{Var}= "f$flow->{Ix}";
 %      push @flows, $flow;
-<& dumpqueryresults:row, sth => $sth, row => $flow &>
+<& dumptable:row, sth => $sth, row => $flow &>
 %   }
 %   }
-<& dumpqueryresults:end &>
+<& dumptable:end &>
 % }
 
 % if (!$specific || $confusing || @islandids<=1) {
 % }
 
 % if (!$specific || $confusing || @islandids<=1) {