Skip to content

Instantly share code, notes, and snippets.

@theory
Last active March 4, 2018 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theory/5974a8da40562693185801b2f3569be8 to your computer and use it in GitHub Desktop.
Save theory/5974a8da40562693185801b2f3569be8 to your computer and use it in GitHub Desktop.
diff --git a/lib/App/Sqitch/Engine/pg.pm b/lib/App/Sqitch/Engine/pg.pm
index 71a8d2cc..11e55ca1 100644
--- a/lib/App/Sqitch/Engine/pg.pm
+++ b/lib/App/Sqitch/Engine/pg.pm
@@ -45,15 +45,22 @@ has _psql => (
my $self = shift;
my $uri = $self->uri;
my @ret = ( $self->client );
- for my $spec (
- [ username => $self->username ],
- [ dbname => $uri->dbname ],
- [ host => $uri->host ],
- [ port => $uri->_port ],
- )
- {
- push @ret, "--$spec->[0]" => $spec->[1] if $spec->[1];
+ my @conninfo;
+ for (my ($k, $v) = each %{{
+ username => $self->username,
+ dbname => $uri->dbname,
+ host => $uri->host,
+ port => $uri->_port,
+ $uri->query_params,
+ }}) {
+ next unless defined $v;
+ if ($v =~ /[ '\\]/) {
+ $v =~ s/(['\\])/\\$1/g;
+ $v = "'$v'";
+ }
+ push @conninfo, "k=$v";
}
+ push @ret => join ' ', @conninfo if @conninfo;
if (my %vars = $self->variables) {
push @ret => map {; '--set', "$_=$vars{$_}" } sort keys %vars;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment