diff --git a/dbi/dumpsql b/dbi/dumpsql index 6377762..1106a52 100755 --- a/dbi/dumpsql +++ b/dbi/dumpsql @@ -55,6 +55,7 @@ my $vertical; # use vertical output format my $escape; # escape non-printable characters my $xhtml; # produce XHTML output my $style; # produce XHTML output +my $separator; # if set, produce CSV with this separator and double-quoted fields GetOptions( 'help|?' => \$help, @@ -62,6 +63,7 @@ GetOptions( 'xhtml' => \$xhtml, 'escape' => \$escape, 'style:s' => \$style, + 'separator:s' => \$separator, ) || pod2usage(2); pod2usage(1) if $help; @@ -163,6 +165,18 @@ if ($xhtml) { } print "\n"; } +} elsif ($separator) { + no warnings 'uninitialized'; + print join($separator, @{$sth->{NAME}}), "\n"; + while (my @a = $sth->fetchrow_array()) { + for (@a) { + if (/[$separator"]/) { + s/"/""/g; + s/.*/"$&"/; + } + } + print join($separator, @a), "\n"; + } } else { no warnings 'uninitialized'; print join("\t", @{$sth->{NAME}}), "\n";