Add database creation to installer.

It's not enough to create tables, one should
create the database first if it is still
missing ...

Signed-off-by: Thomas Hochstein <thh@inter.net>
This commit is contained in:
Thomas Hochstein 2011-01-12 16:41:21 +01:00
parent da6fc073ee
commit 36cffe7aed

View file

@ -47,6 +47,10 @@ my %Conf = %{ReadConfig($HomePath.'/newsstats.conf')};
##### Database table definitions ##### Database table definitions
##### -------------------------------------------------------------------------- ##### --------------------------------------------------------------------------
my $DBCreate = <<SQLDB;
CREATE DATABASE IF NOT EXISTS `$Conf{'DBDatabase'}` DEFAULT CHARSET=utf8;
SQLDB
my %DBCreate = ('DBTableRaw' => <<RAW, 'DBTableGrps' => <<GRPS); my %DBCreate = ('DBTableRaw' => <<RAW, 'DBTableGrps' => <<GRPS);
-- --
-- Table structure for table DBTableRaw -- Table structure for table DBTableRaw
@ -150,6 +154,23 @@ UPGRADE
##### --------------------------- End of definitions --------------------------- ##### --------------------------- End of definitions ---------------------------
### create DB, if necessary
if (!$OptUpdate) {
print "----------\nStarting database creation.\n";
# create database
# we can't use InitDB() as that will use a table name of
# the table that doesn't exist yet ...
my $DBHandle = DBI->connect(sprintf('DBI:%s:host=%s',$Conf{'DBDriver'},
$Conf{'DBHost'}), $Conf{'DBUser'},
$Conf{'DBPw'}, { PrintError => 0 });
my $DBQuery = $DBHandle->prepare($DBCreate);
$DBQuery->execute() or &Bleat(2, sprintf("Can't create database %s: %s%\n",
$Conf{'DBDatabase'}, $DBI::errstr));
printf("Database table %s created succesfully.\n",$Conf{'DBDatabase'});
$DBHandle->disconnect;
};
### DB init, read list of tables ### DB init, read list of tables
print "Reading database information.\n"; print "Reading database information.\n";
my $DBHandle = InitDB(\%Conf,1); my $DBHandle = InitDB(\%Conf,1);
@ -158,7 +179,6 @@ my %TablesInDB =
if (!$OptUpdate) { if (!$OptUpdate) {
##### installation mode ##### installation mode
print "----------\nStarting database table generation.\n";
# check for tables and create them, if they don't exist yet # check for tables and create them, if they don't exist yet
foreach my $Table (keys %DBCreate) { foreach my $Table (keys %DBCreate) {
&CreateTable($Table); &CreateTable($Table);