From: Moritz Bunkus Date: Wed, 2 Dec 2020 09:07:44 +0000 (+0100) Subject: LXDebug dump_sql_result: Spaltenanordnung je nach Inhalt X-Git-Tag: kivitendo-mebil_0.1-0~9^2~581 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=42985d5fd1375d137ddcb32b2601fa7b0f98f042;p=kivitendo-erp.git LXDebug dump_sql_result: Spaltenanordnung je nach Inhalt Spalten, die komplett numerisch sind, werden rechtsbündig angeordnet; alle anderen linksbündig. --- diff --git a/SL/LXDebug.pm b/SL/LXDebug.pm index 0503dcb6c..a1e19767c 100644 --- a/SL/LXDebug.pm +++ b/SL/LXDebug.pm @@ -19,8 +19,9 @@ use constant FILE_TARGET => 0; use constant STDERR_TARGET => 1; use Data::Dumper; +use List::MoreUtils qw(all); use POSIX qw(strftime getpid); -use Scalar::Util qw(blessed refaddr weaken); +use Scalar::Util qw(blessed refaddr weaken looks_like_number); use Time::HiRes qw(gettimeofday tv_interval); use SL::Request (); use SL::YAML; @@ -231,8 +232,14 @@ sub dump_sql_result { map { $column_lengths{$_} = length $row->{$_} if (length $row->{$_} > $column_lengths{$_}) } keys %{ $row }; } + my %alignment; + foreach my $column (keys %column_lengths) { + my $all_look_like_number = all { (($_->{$column} // '') eq '') || looks_like_number($_->{$column}) } @{ $results }; + $alignment{$column} = $all_look_like_number ? '' : '-'; + } + my @sorted_names = sort keys %column_lengths; - my $format = join '|', map { '%' . $column_lengths{$_} . 's' } @sorted_names; + my $format = join '|', map { '%' . $alignment{$_} . $column_lengths{$_} . 's' } @sorted_names; $prefix .= ' ' if $prefix;