]> xenbits.xensource.com Git - people/liuw/osstest.git/commitdiff
mg-show-flight-runvars: calculate @colsw from @rows not via SQL
authorIan Campbell <ian.campbell@citrix.com>
Mon, 1 Feb 2016 14:28:30 +0000 (14:28 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Mon, 8 Feb 2016 16:31:48 +0000 (16:31 +0000)
This will work even once @rows is not all collected by the same SQL
statement.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
mg-show-flight-runvars

index 0995430f535f04c95a85fe9b5342e9edf12cedc0..0cf4e13f18746b33a3f0a4e29b12c968ec27adca 100755 (executable)
@@ -46,7 +46,6 @@ die unless @ARGV==1 && $ARGV[0] =~ m/^\w+$/;
 
 our @cols = qw(job name val);
 our @rows;
-our @colws;
 
 sub collect ($) {
     my ($flight) = @_;
@@ -54,9 +53,6 @@ sub collect ($) {
     $flight =~ m/^\d+/ or $flight = "'$flight'";
     my $qfrom = "FROM runvars WHERE flight=$flight AND $synthcond";
 
-    @colws = $dbh_tests->selectrow_array
-       ("SELECT ".(join ',', map { "max(length($_))" } @cols)." $qfrom");
-
     my $q = $dbh_tests->prepare
        ("SELECT synth, ".(join ',', @cols)." $qfrom ORDER BY synth, name, job");
     $q->execute();
@@ -68,10 +64,15 @@ sub collect ($) {
     }
 }
 
-$colws[1] += length $synthsufx;
-
 collect($ARGV[0]);
 
+our @colws;
+sub max ($$) { $_[$_[0] < $_[1]] }
+foreach my $row (@rows) {
+    @colws = map { max($colws[$_]//0,length($row->[$_])) } qw(0 1 2)
+}
+$colws[1] += length $synthsufx;
+
 foreach my $row (@rows) {
     printf "%-*s %-*s %-*s\n", map { $colws[$_], $row->[$_] } qw(0 1 2)
         or die $!;