From 61bd0898baf098032eef7635ae814bf2dde1b5c5 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 11 Jan 2007 09:12:23 +0000 Subject: [PATCH] Beim Anlegen einer Datenbank die bei "Als Vorlage verwenden" eingetragene Datenbank auch wirklich als Vorlage verwenden. --- SL/User.pm | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/SL/User.pm b/SL/User.pm index ae61fd262..3b36f310c 100644 --- a/SL/User.pm +++ b/SL/User.pm @@ -355,20 +355,33 @@ sub dbcreate { my ($self, $form) = @_; + $form->{sid} = $form->{dbdefault}; + &dbconnect_vars($form, $form->{dbdefault}); + my $dbh = + DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}) + or $form->dberror; + my %dbcreate = ( 'Pg' => qq|CREATE DATABASE "$form->{db}"|, 'Oracle' => qq|CREATE USER "$form->{db}" DEFAULT TABLESPACE USERS TEMPORARY TABLESPACE TEMP IDENTIFIED BY "$form->{db}"| ); - $dbcreate{Pg} .= " WITH ENCODING = '$form->{encoding}'" if $form->{encoding}; + my %dboptions = ( + 'Pg' => [], + ); + + push(@{$dboptions{"Pg"}}, "ENCODING = " . $dbh->quote($form->{"encoding"})) + if ($form->{"encoding"}); + if ($form->{"dbdefault"}) { + my $dbdefault = $form->{"dbdefault"}; + $dbdefault =~ s/[^a-zA-Z0-9_\-]//g; + push(@{$dboptions{"Pg"}}, "TEMPLATE = $dbdefault"); + } - $form->{sid} = $form->{dbdefault}; - &dbconnect_vars($form, $form->{dbdefault}); - my $dbh = - DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}) - or $form->dberror; my $query = qq|$dbcreate{$form->{dbdriver}}|; + $query .= " WITH " . join(" ", @{$dboptions{"Pg"}}) if (@{$dboptions{"Pg"}}); + $dbh->do($query) || $form->dberror($query); if ($form->{dbdriver} eq 'Oracle') { -- 2.20.1