Tadashi Okoshi
slash****@users*****
2005年 6月 30日 (木) 03:15:01 JST
Index: affelio/lib/Affelio/Managing/AccessLogManager.pm diff -u affelio/lib/Affelio/Managing/AccessLogManager.pm:1.4 affelio/lib/Affelio/Managing/AccessLogManager.pm:1.5 --- affelio/lib/Affelio/Managing/AccessLogManager.pm:1.4 Wed Jun 29 22:34:10 2005 +++ affelio/lib/Affelio/Managing/AccessLogManager.pm Thu Jun 30 03:15:01 2005 @@ -4,7 +4,7 @@ # http://affelio.jp/ (Japan) # http://affelio.jp/ (USA and other area) # -# $Id: AccessLogManager.pm,v 1.4 2005/06/29 13:34:10 slash5234 Exp $ +# $Id: AccessLogManager.pm,v 1.5 2005/06/29 18:15:01 slash5234 Exp $ package Affelio::Managing::AccessLogManager; { @@ -18,6 +18,7 @@ use Affelio::misc::Encoding qw(db_encode db_decode); use Affelio::misc::Debug qw(debug_print); use Affelio::NetLib::Email qw(send_email); + use Affelio::exception::DBException; ####################################################################### #Constructor @@ -77,7 +78,7 @@ @row1 = $sth1->fetchrow_array; }; if($@){ - die("db"); + throw Affelio::exception::DBException($af->{db}->errstr); } if(@row1 == () ){ @@ -86,8 +87,15 @@ ############################## #Get existing max ID my $query2 = 'SELECT max(id) FROM AFuser_CORE_accesslog'; - my $sth2 = $af->{db}->prepare($query2) or die $af->{db}->errstr; - $sth2->execute or die $af->{db}->errstr; + my $sth2; + eval{ + $sth2 = $af->{db}->prepare($query2); + $sth2->execute; + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } + my @row2 = $sth2->fetchrow_array; $maxid = $row2[0]; if(defined($row2[0])){ @@ -102,8 +110,14 @@ my $newid2=0; my $maxid2=0; if($afid =~ /http/){ $query2 = 'SELECT max(id2) FROM AFuser_CORE_accesslog'; - $sth2 = $af->{db}->prepare($query2) or die $af->{db}->errstr; - $sth2->execute or die $af->{db}->errstr; + eval{ + $sth2 = $af->{db}->prepare($query2); + $sth2->execute; + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } + @row2 = $sth2->fetchrow_array; $maxid2 = $row2[0]; if(defined($row2[0])){ @@ -124,7 +138,7 @@ $sth3->execute(); }; if($@){ - die("db"); + throw Affelio::exception::DBException($af->{db}->errstr); } } } @@ -155,9 +169,14 @@ ############################## #retrieve all friend records from DB my $query = "SELECT * FROM AFuser_CORE_accesslog WHERE timestamp > $from AND timestamp < $to order by id desc"; - my $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute or die $af->{db}->errstr; - + my $sth; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute; + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } return($sth); } Index: affelio/lib/Affelio/Managing/ApplicationManager.pm diff -u affelio/lib/Affelio/Managing/ApplicationManager.pm:1.4 affelio/lib/Affelio/Managing/ApplicationManager.pm:1.5 --- affelio/lib/Affelio/Managing/ApplicationManager.pm:1.4 Sat Jun 25 21:14:06 2005 +++ affelio/lib/Affelio/Managing/ApplicationManager.pm Thu Jun 30 03:15:01 2005 @@ -4,7 +4,7 @@ # http://affelio.jp/ (Japan) # http://affelio.jp/ (USA and other area) # -# $Id: ApplicationManager.pm,v 1.4 2005/06/25 12:14:06 slash5234 Exp $ +# $Id: ApplicationManager.pm,v 1.5 2005/06/29 18:15:01 slash5234 Exp $ package Affelio::Managing::ApplicationManager; { @@ -152,8 +152,14 @@ ############################## #retrieve all permission records from DB my $query = 'SELECT * FROM AFuser_' . $app_name . '_permission'; - my $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute or die $af->{db}->errstr; + my $sth; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute; + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } debug_print("get_all_premission: end"); return($sth); @@ -255,8 +261,14 @@ #debug_print("AppManager::update_permission q=[$query]"); #access DB - my $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute or die $af->{db}->errstr; + my $sth; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute; + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } #debug_print("AppManager::update_permission end."); } Index: affelio/lib/Affelio/Managing/GroupManager.pm diff -u affelio/lib/Affelio/Managing/GroupManager.pm:1.3 affelio/lib/Affelio/Managing/GroupManager.pm:1.4 --- affelio/lib/Affelio/Managing/GroupManager.pm:1.3 Sun Jun 26 23:20:39 2005 +++ affelio/lib/Affelio/Managing/GroupManager.pm Thu Jun 30 03:15:01 2005 @@ -4,7 +4,7 @@ # http://affelio.jp/ (Japan) # http://affelio.jp/ (USA and other area) # -# $Id: GroupManager.pm,v 1.3 2005/06/26 14:20:39 slash5234 Exp $ +# $Id: GroupManager.pm,v 1.4 2005/06/29 18:15:01 slash5234 Exp $ package Affelio::Managing::GroupManager; { @@ -50,8 +50,15 @@ ############################## #Get existing max ID my $query = 'SELECT max(gid) FROM AFuser_CORE_group'; - my $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute or die $af->{db}->errstr; + my $sth; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute; + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } + my @row = $sth->fetchrow_array; my $maxid = $row[0]; if(defined($row[0])){ @@ -64,8 +71,13 @@ ############################## #Insert a new record $query = 'insert into AFuser_CORE_group(gid, group_name, members, option_pid) values (?,?,?,?)'; - $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute($maxid+1, $group_name, ",", -1) or die $af->{db}->errstr; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute($maxid+1, $group_name, ",", -1); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } debug_print("add_group: end."); return($maxid+1); @@ -82,14 +94,27 @@ my $af = $self->{af}; my $query1 = 'SELECT option_pid FROM AFuser_CORE_group WHERE gid = ?'; - my $sth1 = $af->{db}->prepare($query1) or die $af->{db}->errstr; - $sth1->execute($gid) or die $af->{db}->errstr; + my $sth1; + eval{ + $sth1 = $af->{db}->prepare($query1); + $sth1->execute($gid); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } + my @row1 = $sth1->fetchrow_array; my $perm_id = $row1[0]; my $query2 = 'DELETE FROM AFuser_CORE_group WHERE gid = ?'; - my $sth2 = $af->{db}->prepare($query2) or die $af->{db}->errstr; - $sth2->execute($gid) or die $af->{db}->errstr; + my $sth2; + eval{ + $sth2 = $af->{db}->prepare($query2); + $sth2->execute($gid); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } use Affelio::Managing::PermissionManager; $af->{perm}->remove_permission_by_pid($perm_id); @@ -111,8 +136,14 @@ ############################## #Update DB my $query = "update AFuser_CORE_group set group_name = '$new_name' where gid = $gid"; - my $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute or die $af->{db}->errstr; + my $sth; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute; + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } debug_print("rename_group: end."); } @@ -129,8 +160,15 @@ my $af = $self->{af}; my $query = 'SELECT members FROM AFuser_CORE_group WHERE gid = ?'; - my $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute($gid); + my $sth; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute($gid); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } + my @row = $sth->fetchrow_array; if(!@row){ @@ -157,8 +195,14 @@ ############################## #retrieve a friend record from DB my $query = 'SELECT * FROM AFuser_CORE_group WHERE gid = ?'; - my $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute($gid) or die $af->{db}->errstr; + my $sth; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute($gid); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } my @row = $sth->fetchrow_array; if(!@row){ @@ -183,8 +227,13 @@ ############################## #Update DB $query = "update AFuser_CORE_group set members = '$new_mem' where gid = $gid"; - $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute or die $af->{db}->errstr; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute; + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } debug_print("add_member: end."); } @@ -221,8 +270,14 @@ my $af = $self->{af}; my $query = 'SELECT members FROM AFuser_CORE_group WHERE gid = ?'; - my $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute($gid) or die $af->{db}->errstr; + my $sth; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute($gid); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } my @row = $sth->fetchrow_array; if(!@row){ @@ -235,8 +290,14 @@ debug_print("remove_member: Member($gid) = ($row[0]) (after)"); my $query2 = "update AFuser_CORE_group set members = '$row[0]' where gid = $gid"; - my $sth2 = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth2->execute or die $af->{db}->errstr; + my $sth2; + eval{ + $sth2= $af->{db}->prepare($query); + $sth2->execute; + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } debug_print("remove_member: end."); return; @@ -260,8 +321,14 @@ ############################## #retrieve a friend record from DB - my $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute() or die $af->{db}->errstr; + my $sth; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute(); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } return($sth); } @@ -284,8 +351,14 @@ ############################## #retrieve a friend record from DB - my $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute() or die $af->{db}->errstr; + my $sth; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute(); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } return($sth); } @@ -303,8 +376,14 @@ ############################## #retrieve all friend records from DB my $query = 'SELECT * FROM AFuser_CORE_group'; - my $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute or die $af->{db}->errstr; + my $sth; + eval{ + $sth= $af->{db}->prepare($query); + $sth->execute; + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } return($sth); } @@ -343,8 +422,14 @@ ############################## #Update DB my $query = "update AFuser_CORE_group set members = '$uids_str' where gid = $gid"; - my $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute or die $af->{db}->errstr; + my $sth; + eval{ + $sth= $af->{db}->prepare($query); + $sth->execute; + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } debug_print("set_member_by_string: end."); } @@ -363,8 +448,14 @@ ############################## #Update DB my $query = "update AFuser_CORE_group set option_pid = $pid where gid = $gid"; - my $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute or die $af->{db}->errstr; + my $sth; + eval{ + $sth= $af->{db}->prepare($query); + $sth->execute; + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } debug_print("set_pid: end."); } Index: affelio/lib/Affelio/Managing/MessageManager.pm diff -u affelio/lib/Affelio/Managing/MessageManager.pm:1.5 affelio/lib/Affelio/Managing/MessageManager.pm:1.6 --- affelio/lib/Affelio/Managing/MessageManager.pm:1.5 Tue Jun 28 23:07:21 2005 +++ affelio/lib/Affelio/Managing/MessageManager.pm Thu Jun 30 03:15:01 2005 @@ -4,7 +4,7 @@ # http://affelio.jp/ (Japan) # http://affelio.jp/ (USA and other area) # -# $Id: MessageManager.pm,v 1.5 2005/06/28 14:07:21 slash5234 Exp $ +# $Id: MessageManager.pm,v 1.6 2005/06/29 18:15:01 slash5234 Exp $ package Affelio::Managing::MessageManager; { @@ -18,6 +18,7 @@ use Affelio::misc::Encoding qw(db_encode db_decode); use Affelio::misc::Debug qw(debug_print); use Affelio::NetLib::Email qw(send_email); + use Affelio::exception::DBException; ####################################################################### #Constructor @@ -49,8 +50,14 @@ debug_print("MM::get_unread_message_num: start"); my $af = $self->{af}; - my $sth = $af->{db}->prepare(q{SELECT * FROM AFuser_CORE_message where readflag=0}) or die $af->{db}->errstr; - $sth->execute or die $af->{db}->errstr; + my $sth; + eval{ + $sth = $af->{db}->prepare(q{SELECT * FROM AFuser_CORE_message where readflag=0}); + $sth->execute; + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } my $count=0; while(my @row = $sth->fetchrow_array){ @@ -72,8 +79,14 @@ my $af = $self->{af}; my $query = "update AFuser_CORE_message set readflag = 1 where mid = $mid"; - my $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute; + my $sth; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute; + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } debug_print("MM::retrieve_all: end"); return(); @@ -93,8 +106,14 @@ ############################## #retrieve all friend records from DB - my $sth = $af->{db}->prepare(q{SELECT * FROM AFuser_CORE_message order by timestamp desc}) or die $af->{db}->errstr; - $sth->execute; + my $sth; + eval{ + $sth = $af->{db}->prepare(q{SELECT * FROM AFuser_CORE_message order by timestamp desc}); + $sth->execute; + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } debug_print("MM::retrieve_all: end"); return($sth); @@ -114,8 +133,15 @@ ############################## #retrieve all friend records from DB - my $sth = $af->{db}->prepare("SELECT * FROM AFuser_CORE_message where mid = $mid") or die $af->{db}->errstr; - $sth->execute; + my $sth; + eval{ + $sth = $af->{db}->prepare("SELECT * FROM AFuser_CORE_message where mid = $mid"); + $sth->execute; + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } + my @row = $sth->fetchrow_array; if(!@row){ @@ -150,8 +176,15 @@ ############################## #Get existing max ID - my $sth = $af->{db}->prepare(q{SELECT max(mid) FROM AFuser_CORE_message}) or die $af->{db}->errstr; - $sth->execute; + my $sth; + eval{ + $sth = $af->{db}->prepare(q{SELECT max(mid) FROM AFuser_CORE_message}); + $sth->execute; + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } + my @row = $sth->fetchrow_array; my $maxid = $row[0]; if(defined($row[0])){ @@ -172,8 +205,13 @@ ############################## #Insert a new record my $str10 = "insert into AFuser_CORE_message(msgbody, mid, timestamp, msgtitle, msgtype, msgfrom, readflag) values ('$body', $newid, '$cur_time', '$title', '$type', '$from', 0)"; - $sth = $af->{db}->prepare($str10) or die $af->{db}->errstr; - $sth->execute or die $af->{db}->errstr; + eval{ + $sth = $af->{db}->prepare($str10); + $sth->execute; + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } undef($sth); ############################## Index: affelio/lib/Affelio/Managing/PermissionManager.pm diff -u affelio/lib/Affelio/Managing/PermissionManager.pm:1.2 affelio/lib/Affelio/Managing/PermissionManager.pm:1.3 --- affelio/lib/Affelio/Managing/PermissionManager.pm:1.2 Sat Jun 25 21:14:06 2005 +++ affelio/lib/Affelio/Managing/PermissionManager.pm Thu Jun 30 03:15:01 2005 @@ -4,7 +4,7 @@ # http://affelio.jp/ (Japan) # http://affelio.jp/ (USA and other area) # -# $Id: PermissionManager.pm,v 1.2 2005/06/25 12:14:06 slash5234 Exp $ +# $Id: PermissionManager.pm,v 1.3 2005/06/29 18:15:01 slash5234 Exp $ package Affelio::Managing::PermissionManager; { @@ -16,6 +16,7 @@ use Affelio; use Affelio::misc::CGIError; use Affelio::misc::Debug qw(debug_print); + use Affelio::exception::DBException; ######################################################################## #Constructor @@ -60,8 +61,15 @@ #Decide $newid my $query = 'SELECT max(pid) FROM AFuser_CORE_permission'; - my $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute or die $af->{db}->errstr; + my $sth; + eval{ + $sth= $af->{db}->prepare($query); + $sth->execute; + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } + my @row = $sth->fetchrow_array; my $maxid = $row[0]; if(defined($row[0])){ @@ -84,8 +92,14 @@ debug_print("add_permission q=[$query]"); #DB access - $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute($newid, $type, $id) or die $af->{db}->errstr; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute($newid, $type, $id); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } + debug_print("add_permission DB access done."); #Set new_id into Friend table or Group table @@ -93,7 +107,12 @@ } if($type eq "p"){ #Set this new pid into Friend table record. - $af->{fm}->set_attribute_by_id($id, "option_pid", $newid); + try{ + $af->{fm}->set_attribute_by_id($id, "option_pid", $newid); + }catch Affelio::exception::DBException with { + my $e = shift; + throw $e; + }; } if($type eq "g"){ #Set this new pid into Group table record. @@ -134,8 +153,14 @@ debug_print("update_permission q=[$query]"); #access DB - my $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute or die $af->{db}->errstr; + my $sth; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute; + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } debug_print("PermissionManager::update_permission end."); } @@ -154,8 +179,14 @@ my $query = "SELECT * FROM AFuser_CORE_permission where type='$type' and target_id='$id'"; debug_print("get_permission end: q=[$query]"); - my $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute or die $af->{db}->errstr; + my $sth; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute; + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } debug_print("get_permission end."); return($sth); @@ -173,9 +204,16 @@ my $af = $self->{af}; my $query = 'SELECT * FROM AFuser_CORE_permission WHERE pid = ?'; - my $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute($pid) or die $af->{db}->errstr; - + + my $sth; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute($pid); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } + debug_print("get_permission_by_pid end."); return($sth); } @@ -191,8 +229,14 @@ my $af = $self->{af}; my $query = 'DELETE FROM AFuser_CORE_permission WHERE pid = ?'; - my $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute($pid) or die $af->{db}->errstr; + my $sth; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute($pid); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } debug_print("remove_permission_by_pid end."); } @@ -211,8 +255,15 @@ ############################## #retrieve all permission records from DB my $query = 'SELECT * FROM AFuser_CORE_permission'; - my $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute or die $af->{db}->errstr; + + my $sth; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute; + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } debug_print("get_all_premission: end"); return($sth); Index: affelio/lib/Affelio/Managing/ProfileManager.pm diff -u affelio/lib/Affelio/Managing/ProfileManager.pm:1.2 affelio/lib/Affelio/Managing/ProfileManager.pm:1.3 --- affelio/lib/Affelio/Managing/ProfileManager.pm:1.2 Sat Jun 25 21:14:06 2005 +++ affelio/lib/Affelio/Managing/ProfileManager.pm Thu Jun 30 03:15:01 2005 @@ -4,7 +4,7 @@ # http://affelio.jp/ (Japan) # http://affelio.jp/ (USA and other area) # -# $Id: ProfileManager.pm,v 1.2 2005/06/25 12:14:06 slash5234 Exp $ +# $Id: ProfileManager.pm,v 1.3 2005/06/29 18:15:01 slash5234 Exp $ package Affelio::Managing::ProfileManager; { @@ -16,6 +16,7 @@ use lib("../../"); use Affelio::misc::CGIError; use Affelio::misc::Debug qw(debug_print); + use Affelio::exception::DBException; ####################################################################### #Constructor @@ -42,10 +43,6 @@ return $self; } - ####################################################################### - #Destructor - ####################################################################### - ####################################################################### #save_profile @@ -61,7 +58,12 @@ $key2 =~ s/user__//g; debug_print("ProfileManager::save_profile: $key2 = $af->{$key}"); if($af->{$key} ne ""){ - save_profile_value($self, $key2, $af->{$key}); + try{ + save_profile_value($self, $key2, $af->{$key}); + }catch Affelio::exception::DBException with { + my $e = shift; + throw $e; + }; } } } @@ -69,6 +71,51 @@ return(""); } + sub save_profile_value{ + my $self = shift; + my $af = $self->{af}; + my $attribute = shift; + my $value = shift; + + debug_print("ProfileManager::save_profile_value: ($attribute) = ($value)"); + + my $query = "SELECT * FROM AFuser_CORE_prof where attribute = '$attribute'"; + my $sth1; + eval{ + $sth1 = $af->{db}->prepare($query); + $sth1->execute; + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } + + my @result= $sth1->fetchrow_array(); + if(@result==()){ + my $query2 = 'insert into AFuser_CORE_prof(attribute, value) values (?,?)'; + my $sth2; + eval{ + $sth2 = $af->{db}->prepare($query2); + $sth2->execute($attribute, $value); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } + + }else{ + my $query3 = "update AFuser_CORE_prof set value = '$value' where attribute = '$attribute'"; + + my $sth3; + eval{ + $sth3 = $af->{db}->prepare($query3); + $sth3->execute; + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } + } + } + + ####################################################################### #load_profile ####################################################################### @@ -78,7 +125,14 @@ debug_print("ProfileManager::load_profile: start."); - my $SQL_profattr = load_profile_table($self); + my $SQL_profattr; + + try{ + $SQL_profattr = load_profile_table($self); + }catch Affelio::exception::DBException with { + my $e = shift; + throw $e; + }; my $attribute=""; my $value=""; while( ($attribute, $value) = $SQL_profattr->fetchrow_array){ @@ -91,24 +145,6 @@ return(""); } - - ######################################################################## - #get_attribute_table - # returns SQL_result (aid, name, type) x records - ######################################################################## - sub get_attribute_table{ - my $self = shift; - my $af = $self->{af}; - - ############################## - #retrieve all friend records from DB - my $query = 'SELECT * FROM AFuser_CORE_prof_attr'; - my $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute or die $af->{db}->errstr; - - return($sth); - } - ######################################################################## #load_profile_table # returns SQL_result (attribute, value) x records @@ -120,39 +156,42 @@ my $sth; my $query = 'SELECT * FROM AFuser_CORE_prof'; - try{ + eval{ $sth = $af->{db}->prepare($query); $sth->execute(); - }catch Error with { - my $ex = shift; + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); }; return($sth); } - sub save_profile_value{ + ######################################################################## + #get_attribute_table + # returns SQL_result (aid, name, type) x records + ######################################################################## + sub get_attribute_table{ my $self = shift; my $af = $self->{af}; - my $attribute = shift; - my $value = shift; - debug_print("ProfileManager::save_profile_value: ($attribute) = ($value)"); + ############################## + #retrieve all friend records from DB + my $query = 'SELECT * FROM AFuser_CORE_prof_attr'; + my $sth; - my $query = "SELECT * FROM AFuser_CORE_prof where attribute = '$attribute'"; - my $sth1 = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth1->execute or die $af->{db}->errstr; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute; + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + }; - my @result= $sth1->fetchrow_array(); - if(@result==()){ - my $query2 = 'insert into AFuser_CORE_prof(attribute, value) values (?,?)'; - my $sth2 = $af->{db}->prepare($query2) or die $af->{db}->errstr; - $sth2->execute($attribute, $value) or die $af->{db}->errstr; - }else{ - my $query3 = "update AFuser_CORE_prof set value = '$value' where attribute = '$attribute'"; - my $sth3 = $af->{db}->prepare($query3) or die $af->{db}->errstr; - $sth3->execute or die $af->{db}->errstr; - } + return($sth); } + + }#package 1;