From: Moritz Bunkus Date: Thu, 11 Jan 2007 09:12:23 +0000 (+0000) Subject: Beim Anlegen einer Datenbank die bei "Als Vorlage verwenden" eingetragene Datenbank... X-Git-Tag: release-2.4.1~1^2~64 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=61bd0898baf098032eef7635ae814bf2dde1b5c5;p=kivitendo-erp.git Beim Anlegen einer Datenbank die bei "Als Vorlage verwenden" eingetragene Datenbank auch wirklich als Vorlage verwenden. --- 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') {