Commit bd117a07 authored by Leigh Stoller's avatar Leigh Stoller

Redo my DBexists() addition since it got conflicted away by last

revision.
parent 179c189f
......@@ -66,6 +66,25 @@ sub pid($) { return $_[0]->{'PID'}; };
sub dbh($) { return $_[0]->{'DBH'}; };
sub dbname($) { return $_[0]->{'DBNAME'}; };
#
# Check for existence of DB
#
sub DBExists($$)
{
my ($class, $dbname) = @_;
require Mysql;
$Mysql::QUIET = 1;
my $dbh = Mysql->connect("localhost");
return undef
if (!defined($dbh));
my @dbs = $dbh->listdbs();
return 1
if (grep {$_ eq $dbname} @dbs);
return 0;
}
#
# Need to wrap the return value. See below.
#
......@@ -135,6 +154,21 @@ sub pid($) { return $_[0]->{'PID'}; };
sub dbh($) { return $_[0]->{'DBH'}; };
sub dbname($) { return $_[0]->{'DBNAME'}; };
#
# Check for existence of DB
#
sub DBExists($$)
{
my ($class, $dbname) = @_;
require DBI;
my @dbs = DBI->data_sources("mysql");
return 1
if (grep {$_ eq "DBI:mysql:$dbname"} @dbs);
return 0;
}
#
# Wrap query for proper DBI syntax.
#
......@@ -354,6 +388,21 @@ $DBErrorString = "";
my $queryCount = 0;
#
# Does DB exist yet.
#
sub DBExists($)
{
my ($dbname) = @_;
if ($DBCONN_USEDBI) {
return emdbi_wrapper::DBI->DBExists($dbname);
}
else {
return emdbi_wrapper::Mysql->DBExists($dbname);
}
}
sub TBDBConnect($$)
{
my ($dbnum, $dbname) = @_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment