Skip to content

Commit

Permalink
[Pg] escape connection params
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Aug 28, 2012
1 parent b3973e7 commit c3ef1ca
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/DBDish/Pg.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -455,13 +455,18 @@ class DBDish::Pg:auth<mberends>:ver<0.0.1> {
has $!errstr;
method !errstr() is rw { $!errstr }

sub quote-and-escape($s) {
"'" ~ $s.trans([q{'}, q{\\]}] => [q{\\\'}, q{\\\\}])
~ "'"
}

#------------------ methods to be called from DBIish ------------------
method connect(*%params) {
my $host = %params<host> // 'localhost';
my $port = %params<port> // 5432;
my $database = %params<dbname> // %params<database> // 'postgres';
my $user = %params<user> // die 'Missing <user> config';
my $password = %params<password> // die 'Missing <password> config';
my $host = quote-and-escape %params<host> // 'localhost';
my $port = quote-and-escape %params<port> // 5432;
my $database = quote-and-escape %params<dbname> // %params<database> // 'postgres';
my $user = quote-and-escape %params<user> // die 'Missing <user> config';
my $password = quote-and-escape %params<password> // die 'Missing <password> config';
my $conninfo = "host=$host port=$port dbname=$database user=$user password=$password";
my $pg_conn = PQconnectdb($conninfo);
my $status = PQstatus($pg_conn);
Expand Down

0 comments on commit c3ef1ca

Please sign in to comment.