diff --git a/SetupNewComp.pl b/SetupNewComp.pl index e032011..b548771 100755 --- a/SetupNewComp.pl +++ b/SetupNewComp.pl @@ -85,8 +85,8 @@ sub setCompanyDBSet { or die getTimeStamp("log") . " - pid $$ >> Could not connect to admin database: $DBI::errstr"; - $company_db_user = sprintf "dbu%013s", $company_id; - $company_db_name = sprintf "dbn%013s", $company_id; + $company_db_user = sprintf "dbu%08s", $company_id; + $company_db_name = sprintf "dbn%08s", $company_id; $company_db_pwd = generateRandomPassword(16); my $sth = $dbh->prepare( "update ase_lar.companies set db_user = '" @@ -124,12 +124,9 @@ sub checkCompanyDBGrant() { $exit_rc = 0; } else { - my @results = $sth->fetchrow_array; - print getTimeStamp("log") - . " - pid $$ >> query result: " - . $results[0] . ".\n"; - - if ( ( scalar @results ) == 1 ) { $exit_rc = 0 } + my $results = $sth->fetchall_arrayref; + my @arr_res = @{$results}; + if ( @arr_res == 1 ) { $exit_rc = 0 } } $sth->finish; @@ -177,6 +174,22 @@ sub setCompanyDBGrant() { return 1; } +sub checkCompanyDBTables() { + my $dbh = + DBI->connect( "DBI:mysql:$db_adm;host=$db_adm_srv", 'root', $db_root_pwd ) + or die getTimeStamp("log") + . " - pid $$ >> Could not connect to db server: $DBI::errstr"; + + my $sth_db = + $dbh->prepare( "CREATE DATABASE IF NOT EXISTS " + . $company_db_name + . " CHARACTER SET utf8 COLLATE utf8_general_ci;" ) + or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr"; + $sth_db->execute() + or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr"; + $sth_db->finish; +} + print getTimeStamp("log") . " - pid $$ >> Execution started.\n"; GetOptions( "company=s" => \$company ) @@ -190,13 +203,9 @@ if ( !checkCompanyDBSet() ) { if ( !checkCompanyDBGrant() ) { print getTimeStamp("log") . " - pid $$ >> Set Company user DB grant.\n"; setCompanyDBGrant(); + print getTimeStamp("log") . " - pid $$ >> Set Company user DB tables.\n"; + setCompanyDBTables(); } -print $company_db_user . "\n"; -print $company_db_pwd . "\n"; - -my @info = getpwnam('alex'); -print Dumper \@info; - print getTimeStamp("log") . " - pid $$ >> Execution ended.\n"; exit;