Tadashi Okoshi
slash****@users*****
2005年 6月 30日 (木) 03:15:01 JST
Index: affelio/lib/Affelio.pm diff -u affelio/lib/Affelio.pm:1.11 affelio/lib/Affelio.pm:1.12 --- affelio/lib/Affelio.pm:1.11 Wed Jun 29 19:40:16 2005 +++ affelio/lib/Affelio.pm Thu Jun 30 03:15:00 2005 @@ -4,7 +4,7 @@ # http://affelio.jp/ (Japan) # http://affelio.jp/ (USA and other area) # -# $Id: Affelio.pm,v 1.11 2005/06/29 10:40:16 slash5234 Exp $ +# $Id: Affelio.pm,v 1.12 2005/06/29 18:15:00 slash5234 Exp $ package Affelio; { @@ -27,7 +27,8 @@ use Affelio::misc::L10N; use Affelio::misc::WebInput; use Affelio::exception::TaintedInputException; - + use Affelio::exception::DBException; + use Affelio::exception::SystemException; ###################################################################### #Constructor @@ -80,7 +81,6 @@ #caller= "" ... if AffelioCore called me. #caller= "install_name"... if application "install_name" called me. - ################################### #Managers ################################### @@ -191,21 +191,34 @@ if($db_type eq "mysql"){ my $dsn = "DBI:mysql:$db_dbname:$db_hostname:$db_port"; - $self->{db} = DBI->connect($dsn, $db_username, $db_password) or die("Cannot connect to MySQL: " . $DBI::errstr); + eval{ + $self->{db} = DBI->connect($dsn, $db_username, $db_password) or die("Cannot connect to MySQL: " . $DBI::errstr); + }; + if($@){ + throw Affelio::exception::DBException("MySQL open error"); + } }elsif ($db_type eq "sqlite"){ - - $self->{db} = DBI->connect("dbi:SQLite:dbname=$self->{site__user_dir}/DB.sqlite", "", "") or die("Cannot connect to SQLite: " . $DBI::errstr); - + eval{ + $self->{db} = DBI->connect("dbi:SQLite:dbname=$self->{site__user_dir}/DB.sqlite", "", "") or die("Cannot connect to SQLite: " . $DBI::errstr); + }; + if($@){ + throw Affelio::exception::DBException("SQLite open error"); + } }else{ - die("DB type not specified"); + throw Affelio::exception::SystemException("DB type not specified"); } if(!defined($self->{db})){ - die("DB handle error: This error is very weird."); + throw Affelio::exception::DBException("DB Handle not defined after open. very weird."); } - $self->{db}->{RaiseError} = 1; + eval{ + $self->{db}->{RaiseError} = 1; + }; + if($@){ + throw Affelio::exception::DBException("DB Error Setting"); + } } @@ -232,11 +245,29 @@ ###MySQL if($db_type eq "mysql"){ my $dsn = "DBI:mysql:$db_dbname:$db_hostname:$db_port"; - $ret = DBI->connect($dsn, $db_username, $db_password) or die "Cannot connect to AppDB: " . $DBI::errstr; + + eval{ + $ret = DBI->connect($dsn, $db_username, $db_password); + }; + if($@){ + throw Affelio::exception::DBException("MySQL open error"); + } } ###SQLite if($db_type eq "sqlite"){ - $ret = DBI->connect("dbi:SQLite:dbname=$self->{site__user_dir}/appdata/$app_install_name/DB.sqlite", "", "") or die "Cannot connect to AppDB: " . $DBI::errstr; + eval{ + $ret = DBI->connect("dbi:SQLite:dbname=$self->{site__user_dir}/appdata/$app_install_name/DB.sqlite", "", ""); + }; + if($@){ + throw Affelio::exception::DBException("SQLite open error"); + } + } + + eval{ + $ret->{RaiseError} = 1; + }; + if($@){ + throw Affelio::exception::DBException("DB Error Setting"); } $ret->{RaiseError} = 1;