From 69c9ccb917fe450add34907791247223172d0706 Mon Sep 17 00:00:00 2001 From: Elijah Perrault Date: Mon, 14 Feb 2011 11:50:49 -0700 Subject: [PATCH] On second thought, added PostgreSQL support. But official modules do not work with it yet. --- bin/auto | 21 +++++++++++++++++++++ doc/CHANGELOG | 1 + doc/TODO | 2 +- install | 12 ++++++------ 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/bin/auto b/bin/auto index 86c2ea2..847aca3 100755 --- a/bin/auto +++ b/bin/auto @@ -219,6 +219,27 @@ given (lc((conf_get('database:format'))[0][0])) { # # Connect to database. # $DB = DBI->connect("dbi:CSV:f_dir=$Bin/../etc/".(conf_get('database:dir'))[0][0]) or err(2, 'Failed to connect to database!', 1); #} + when ('pgsql') { + # PostgreSQL. + if ($ENFEAT !~ /pgsql/) { err(2, 'Auto not built with PostgreSQL support. Aborting.', 1); } + my @reqcval = qw(database:name database:host database:username database:password); + foreach (@reqcval) { if (!conf_get($_)) { err(2, "Missing required configuration value $_. Aborting.", 1); } } + + # Import DBD::Pg. + require DBD::Pg; + + # Connect to database. + if (conf_get('database:port')) { + # If a specific port was given, use it. + $DB = DBI->connect('dbi:Pg:db='.(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]) or err(2, 'Failed to connect to database!', 1); + } + else { + # We were not given a port, connect using PGPORT (usually 5432) + $DB = DBI->connect('dbi:Pg:db='.(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]) or err(2, 'Failed to connect to database!', 1); + } + } # Unknown database format. default { err(2, 'Unknown database format \''.lc((conf_get('database:format'))[0][0]).'\'. Aborting.', 1); } } diff --git a/doc/CHANGELOG b/doc/CHANGELOG index 8ab7c59..d5bff88 100644 --- a/doc/CHANGELOG +++ b/doc/CHANGELOG @@ -3,6 +3,7 @@ Auto IRC Bot 3.0: Change Log 3.0 Indev =============================================================================== + * Added PostgreSQL support. Official modules do not support this yet. * database:format now a required configuration value. * Added support for MySQL. ./install --with-mysql * Added a database upgrade script for upgrading the `qdb` table in 3.0.0a3 diff --git a/doc/TODO b/doc/TODO index fe45e1d..dcc65b3 100644 --- a/doc/TODO +++ b/doc/TODO @@ -31,7 +31,7 @@ Legend: [O] Implement Auto-Flatfile as the main format [X] Add SQLite support as default [x] Add MySQL support - [O] Add PostgreSQL support + [X] Add PostgreSQL support [O] Add Oracle DB support [O] Sys diff --git a/install b/install index ba177fd..b9b4c83 100755 --- a/install +++ b/install @@ -38,12 +38,12 @@ if (defined $ARGV[0]) { $features .= ' ipv6'; } elsif ($_ eq '--with-mysql') { - $features =~ s/(sqlite|csv)/mysql/g; + $features =~ s/(sqlite|pgsql)/mysql/g; } - #elsif ($_ eq '--with-csv') { - # $features =~ s/(sqlite|mysql)/csv/g; - #} - else { + elsif ($_ eq '--with-pgsql') { + $features =~ s/(sqlite|mysql)/pgsql/g; + } + else { println "Warning: Unknown option '$_'"; } } @@ -105,7 +105,7 @@ println "\0"; modfind('DBI'); modfind('DBD::SQLite') if $features =~ /sqlite/; modfind('DBD::mysql') if $features =~ /mysql/; -modfind('DBD::CSV') if $features =~ /csv/; +modfind('DBD::Pg') if $features =~ /pgsql/; modfind('Class::Unload'); modfind('IO::Socket::INET6') if $features =~ /ipv6/; modfind('IO::Socket::SSL') if $features =~ /ssl/;