From 55bd411e2cab2a8bc95b025253731858fecc1581 Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Fri, 20 Aug 2010 12:39:20 -0500 Subject: [PATCH] remove WebGUI::Utility::makeArrayTabSafe --- lib/WebGUI/SQL.pm | 18 +++++++++++++++--- lib/WebGUI/Utility.pm | 21 +-------------------- t/Utility.t | 9 --------- 3 files changed, 16 insertions(+), 32 deletions(-) diff --git a/lib/WebGUI/SQL.pm b/lib/WebGUI/SQL.pm index a74abb250..32439ec56 100644 --- a/lib/WebGUI/SQL.pm +++ b/lib/WebGUI/SQL.pm @@ -759,12 +759,24 @@ sub quickTab { my $self = shift; my $sql = shift; my $params = shift; + my $sth = $self->prepare($sql); $sth->execute(@{$params}); - my $output = join("\t", $sth->getColumnNames) . "\n"; + + my $csv = Text::CSV_XS->new({ + eol => "\n", + quote_char => undef, + escape_char => undef, + sep_char => "\t", + }); + + return undef + unless $csv->combine($sth->getColumnNames); + + my $output = $csv->string; while (my @data = $sth->fetchrow_array) { - WebGUI::Utility::makeArrayTabSafe(\@data); - $output .= join("\t", @data) . "\n"; + return undef unless $csv->combine(@data); + $output .= $csv->string; } $sth->finish; return $output; diff --git a/lib/WebGUI/Utility.pm b/lib/WebGUI/Utility.pm index e44c426b9..62a662e13 100644 --- a/lib/WebGUI/Utility.pm +++ b/lib/WebGUI/Utility.pm @@ -22,7 +22,7 @@ use Tie::IxHash; use Net::CIDR::Lite; our @ISA = qw(Exporter); -our @EXPORT = qw(&makeTabSafe &makeArrayTabSafe &randomizeHash &randomizeArray &isInSubnet +our @EXPORT = qw(&makeTabSafe &randomizeHash &randomizeArray &isInSubnet &sortHashDescending &sortHash &isIn &makeCommaSafe &randint &round &scalarEquals ); @@ -40,7 +40,6 @@ This package provides miscellaneous but useful utilities to the WebGUI programme use WebGUI::Utility; $boolean = isIn($value, @array); $boolean = isInSubnet($ip, \@subnets); - makeArrayTabSafe(\@array); $string = makeCommaSafe($string); $string = makeTabSafe($string); $integer = randint($low,$high); @@ -122,24 +121,6 @@ sub isInSubnet { #------------------------------------------------------------------- -=head2 makeArrayTabSafe ( array ) - -Searches through an array looking for tabs and replaces them with four spaces. Also replaces carriage returns with a space. This is useful for exporting tab separated data. - -=head3 array - - A reference to the array to look through. The array itself is modified, rather than - returning useful data. - -=cut - -sub makeArrayTabSafe { - my $array = $_[0]; - $_ = makeTabSafe($_) for @$array; -} - -#------------------------------------------------------------------- - =head2 makeCommaSafe ( text ) Replaces commas with semi-colons and carriage returns with spaces. diff --git a/t/Utility.t b/t/Utility.t index 2c541b0b9..4ef57bfa7 100644 --- a/t/Utility.t +++ b/t/Utility.t @@ -51,15 +51,6 @@ is( 'makeCommaSafe(): clearing tabs, newlines and carriage returns' ); -# makeArrayTabSafe -- modifies an array in place -my $tabbedArray = ["this\tthat", "these\nthose"]; -WebGUI::Utility::makeArrayTabSafe($tabbedArray); -cmp_deeply( - $tabbedArray, - ["this that", "these those"], - 'makeArrayTabSafe' -); - # randint my $number = WebGUI::Utility::randint(50,75); ok($number >= 50 && $number <= 75, 'randint()');