Added support for MySQL. This has the side effect of making database:format a required config value.

This commit is contained in:
Elijah Perrault committed 2011-02-13 21:25:29 -07:00
1 parent 27e242bbef
commit fe57f6df3e
3 files changed
+58 -14

No files matched your search

+44 -6
View File
@@ -15,7 +15,6 @@ use Sys::Hostname;
use IO::Socket;
use IO::Select;
use DBI;
use DBD::SQLite;
use Class::Unload;
use FindBin qw($Bin);
our $Bin = $Bin; ## no critic qw(NamingConventions::Capitalization Variables::ProhibitPackageVars)
@@ -144,7 +143,7 @@ if (conf_get('die')) {
}
# Check for required configuration values.
my @REQCVALS = qw(locale expire_logs server fantasy_pf ratelimit);
my @REQCVALS = qw(locale expire_logs server fantasy_pf ratelimit database:format);
foreach my $REQCVAL (@REQCVALS) {
if (!conf_get($REQCVAL)) {
my $err = 2;
@@ -168,11 +167,50 @@ println ' Success';
API::Log::expire_logs();
# Connect to database.
if (!-e "$Bin/../etc/auto.db") {
system "touch $Bin/../etc/auto.db";
system "chmod a+x $Bin/../etc/auto.db";
our $DB;
given (lc((conf_get('database:format'))[0][0])) {
when ('sqlite') {
# SQLite.
if ($ENFEAT !~ /sqlite/) { err(2, 'Auto not built with SQLite support. Aborting.', 1); }
if (!conf_get('database:filename')) { err(2, 'Missing required configuration value database:filename. Aborting.', 1); }
# Import DBD::SQLite.
require DBD::SQLite;
if (!-e "$Bin/../etc/".(conf_get('database:filename'))[0][0]) {
# Create <database:filename> if it's missing.
system "touch $Bin/../etc/".(conf_get('database:filename'))[0][0];
system "chmod a+x $Bin/../etc/".(conf_get('database:filename'))[0][0];
}
# Connect to database.
$DB = DBI->connect("dbi:SQLite:dbname=$Bin/../etc/".(conf_get('database:filename'))[0][0], q{}, q{});
}
when ('mysql') {
# MySQL.
if ($ENFEAT !~ /mysql/) { err(2, 'Auto not built with SQLite support. Aborting.', 1); }
my @reqcval = qw(database:host database:name database:username database:password);
foreach (@reqcval) { if (!conf_get($_)) { err(2, "Missing required configuration value $_. Aborting.", 1); } }
undef @reqcval;
# Import DBD::mysql.
require DBD::mysql;
# Connect to database.
if (conf_get('database:port')) {
# If we were given a port, connect with it.
$DB = DBI->connect('DBI:mysql:database='.(conf_get('database:name'))[0][0].';host='.(conf_get('database:host'))[0][0].';port='.(conf_get('database:port'))[0][0],
(conf_get('database:username'))[0][0], (conf_get('database:password'))[0][0]);
}
else {
# If not, connect without specifying a port.
$DB = DBI->connect('DBI:mysql:database='.(conf_get('database:name'))[0][0].';host='.(conf_get('database:host'))[0][0],
(conf_get('database:username'))[0][0], (conf_get('database:password'))[0][0]);
}
}
# Unknown database format.
default { err(2, 'Unknown database format \''.lc((conf_get('database:format'))[0][0]).'\'. Aborting.', 1); }
}
our $DB = DBI->connect("dbi:SQLite:dbname=$Bin/../etc/auto.db", q{}, q{});
# Ratelimit timer.
Core::IRC::clear_usercmd_timer();