80
80
if ($arg->{dbquotes}) {
81
81
$testdsn =~ s/$alias\s*=(\w+)/'db="'.lc $2.'"'/e;
84
85
$dbh = DBI->connect($testdsn, $testuser, '',
85
86
{RaiseError => 1, PrintError => 0, AutoCommit => 1});
88
if ($@ !~ /domain socket/ or 16 != $helpconnect) {
89
return $helpconnect, $@, undef;
92
## If we created it, and it was shut down, start it up again
93
warn "Restarting test database $testdsn at $testdir\n";
95
my $COM = qq{$pg_ctl -l $testdir/dbdpg_test.logfile -D $testdir start};
97
$COM = qq{su -m $su -c "$COM"};
100
eval { $info = qx{$COM}; };
101
if ($@ or $info !~ /\w/) {
102
$@ = "Could not startup new database ($@) ($info)";
103
return $helpconnect, $@, undef;
105
## Wait for it to startup and verify the connection
110
$dbh = DBI->connect($testdsn, $testuser, '',
111
{RaiseError => 1, PrintError => 0, AutoCommit => 1});
113
if ($@ =~ /starting up/ or $@ =~ /PGSQL\.\d+/) {
89
goto GOTDBH unless $@;
91
if ($@ =~ /invalid connection option/) {
92
return $helpconnect, $@, undef;
95
## If this was created by us, try and restart it
96
if (16 == $helpconnect) {
98
## Bypass if the testdir has been removed
100
warn "Test directory $testdir has been removed, will recreate from scratch\n";
103
warn "Restarting test database $testdsn at $testdir\n";
105
my $COM = qq{$pg_ctl -l $testdir/dbdpg_test.logfile -D $testdir start};
107
$COM = qq{su -m $su -c "$COM"};
110
eval { $info = qx{$COM}; };
111
if ($@ or $info !~ /\w/) {
112
$@ = "Could not startup new database ($@) ($info)";
113
return $helpconnect, $@, undef;
115
## Wait for it to startup and verify the connection
120
$dbh = DBI->connect($testdsn, $testuser, '',
121
{RaiseError => 1, PrintError => 0, AutoCommit => 1});
123
if ($@ =~ /starting up/ or $@ =~ /PGSQL\.\d+/) {
122
return $helpconnect, $@, $dbh;
125
} ## end got an error on connect attempt
127
## We've got a good connection, so do final tweaks and return
132
return $helpconnect, $@, $dbh;
135
## We've got a good connection, so do final tweaks and return
138
} ## end testdir exists
140
} ## end error and we created this database
130
142
} ## end got testdsn and testuser
132
## No previous info, so start connection attempt from scratch
144
## No previous info (or failed attempt), so start new connection attempt from scratch
134
146
$testdsn ||= $ENV{DBI_DSN};
135
147
$testuser ||= $ENV{DBI_USER};