From 3aee99f7f6537390ed7212fed466881a8502b15a Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Mon, 6 Nov 2023 16:59:00 +0100 Subject: [PATCH] Add option --separator --- dbi/dumpsql | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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";