diff --git a/postgresql/CHANGELOG b/postgresql/CHANGELOG index 3201aacf7..add9137d5 100644 --- a/postgresql/CHANGELOG +++ b/postgresql/CHANGELOG @@ -52,3 +52,5 @@ Added access control options to prevent the viewing and management of views, seq Updated the module to run on Windows, and created a default configuration that will sort with the PostgreSQL 8.2 Windows install. ---- Changes since 1.320 ---- When there are too many databases or tables to display, a menu for editing a specific one is displayed in addition to the search field. +---- Changes since 1.340 ---- +Use HTML format output from the pgsql command, to handle queries for rows containing newlines and special characters. diff --git a/postgresql/postgresql-lib.pl b/postgresql/postgresql-lib.pl index c4d758036..1ce53b1d5 100644 --- a/postgresql/postgresql-lib.pl +++ b/postgresql/postgresql-lib.pl @@ -373,7 +373,7 @@ else { # Call the psql program local $host = $config{'host'} ? "-h $config{'host'}" : ""; $host .= " -p $config{'port'}" if ($config{'port'}); - local $cmd = "e_path($config{'psql'}). + local $cmd = "e_path($config{'psql'})." --html". (!&supports_pgpass() ? " -u" : " -U $postgres_login"). " -c "."e_path($sql)." $host $_[0]"; if ($postgres_sameunix && defined(getpwnam($postgres_login))) { @@ -411,44 +411,26 @@ else { "$config{'psql'} failed")); } else { - local $dash = ; - if ($dash =~ /^\s*\+\-/) { - # mysql-style output - $line = ; - $line =~ s/^[\s\|]+//; $line =~ s/[\s\|]+$//; - local @titles = split(/\|/, $line); - map { s/^\s+//; s/\s+$// } @titles; - $line = ; # skip useless dashes - while(1) { - $line = ; - last if (!$line || $line =~ /^\s*\+/); - $line =~ s/^[\s\|]+//; - $line =~ s/[\s\|]+$//; - local @row = split(/\|/, $line); - map { s/^\s+//; s/\s+$// } @row; - push(@data, \@row); + # Read HTML-format output + local $row; + local @data; + while($line = ) { + if ($line =~ /^\s*/) { + # Start of a row + $row = [ ]; } - $rv = { 'titles' => \@titles, 'data' => \@data }; - } - elsif ($dash !~ /^-/) { - # no output, such as from an insert - $rv = undef; - } - else { - # psql-style output - local @titles = split(/\|/, $line); - map { s/^\s+//; s/\s+$// } @titles; - while(1) { - $line = ; - last if (!$line || - $line =~ /^\(\d+\s+\S+\)/); - local @row = split(/\|/, $line); - map { s/^\s+//; s/\s+$// } @row; - push(@data, \@row); + elsif ($line =~ /^\s*<\/tr>/) { + # End of a row + push(@data, $row); + $row = undef; + } + elsif ($line =~ /^\s*<(td|th)[^>]*>([^<]*)<\/(td|th)>/) { + # Value in a row + push(@$row, &entities_to_ascii("$2")); } - $rv = { 'titles' => \@titles, - 'data' => \@data }; } + $rv = { 'titles' => shift(@data), + 'data' => \@data }; } close(OUT); return $rv;