Skip to content

Commit

Permalink
check_database: rework without ISQL
Browse files Browse the repository at this point in the history
Instead of depending on external binary (finding of
which is a burden by itself), try connecting to the
database and find its dialect using the driver
  • Loading branch information
real-dam committed Oct 25, 2011
1 parent b40a214 commit 75b6373
Showing 1 changed file with 21 additions and 51 deletions.
72 changes: 21 additions & 51 deletions t/TestFirebird.pm
Expand Up @@ -404,76 +404,46 @@ sub create_test_database {

=head2 check_database
Using isql CLI to connect to the database and retrieve the dialect.
If I/O error then conclude that the database doesn't exists.
Try to connect and conclude that the database doesn't exist on error.
=cut

sub check_database {
my $self = shift;

my ( $isql, $user, $pass, $path, $host ) = (
$self->{isql}, $self->{user}, $self->{pass},
my ( $user, $pass, $path, $host ) = (
$self->{user}, $self->{pass},
$self->{path}, $self->{host}
);

#- Connect to the test database

print "The isql path is $isql\n";
$path = "$host:$path" if $host;

print "The databse path is $path\n";

my $dialect;
my $database_ok = 1;
my $driver = $self->dbd;
$driver =~ s/^DBD:://;

local $ENV{ISC_USER};
local $ENV{ISC_PASSWORD};
my $dbh = eval {
DBI->connect( "dbi:$driver:database=$path", $user, $pass,
{ RaiseError => 1, PrintError => 0 } );
};

my $ocmd = qq("$isql" -x "$host:$path" 2>&1);
return 0 unless $dbh;

$ENV{ISC_USER} = $user;
$ENV{ISC_PASSWORD} = $pass;
# check the dialect
my $info = $dbh->func('db_sql_dialect', 'ib_database_info');

# print "cmd: $ocmd\n";
eval {
open my $fh, '-|', $ocmd;
LINE:
while (<$fh>) {
my $line = $_;
# Check for I/O error or 'not recognized' ... from cmd.exe
# print "II $line\n";
# The systems LANG setting may be a problem ...
if ($line =~ m{error|recognized}i) {
$database_ok = 0;
last LINE;
}
# Check for Firebird login errors
if ($line =~ m{Firebird login}i) {
print "Please, check your Firebird login parameters.\n";
}
# Get dialect if got here
if ($line =~ m{DIALECT (\d)}i) {
$dialect = $1;
last LINE;
}
}
close $fh;
};
if ($@) {
die "isql open error!\n";
}
$dbh->disconnect;

unless ($database_ok) {
return;
}
die "Unable to retrieve SQL dialect"
unless $info->{db_sql_dialect};

unless (defined $dialect) {
print "No dialect?\n";
return;
}
else {
print "Dialect is $dialect\n";
return $dialect;
}
die "Database dialect wrong ($info->{db_sql_dialect})"
unless $info->{db_sql_dialect} == 3;

return 1;
}

=head2 create_mark
Expand Down

0 comments on commit 75b6373

Please sign in to comment.