diff options
author | Christian Pointner <equinox@helsinki.at> | 2014-09-18 14:34:50 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2014-09-18 14:34:50 (GMT) |
commit | d2df76a89f29acd03383da6a76839435c51e8621 (patch) | |
tree | 08314ad94e501c7a74f7c82eb08dea23a4a98f3c /lib | |
parent | 21d59b1d774f4bba42b36e927b2069fe46cdd6f9 (diff) |
cleanup database handle
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/rddb.pm | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/rddb.pm b/lib/rddb.pm index 1ef296c..a7506a2 100755 --- a/lib/rddb.pm +++ b/lib/rddb.pm @@ -24,12 +24,18 @@ sub opendb return ($dbh, 'OK', 'success'); } +sub closedb +{ + my $dbh = shift; + $dbh->disconnect(); +} + sub get_token { my $username = shift; my ($dbh, $state, $errorstring) = opendb(); - unless($dbh) { + unless(defined $dbh) { return ('', $state, $errorstring); } @@ -40,9 +46,13 @@ sub get_token or return ('', 'ERROR', "Database Error: " . $sth->errstr); my ($token) = $sth->fetchrow_array; - return ($token, 'OK', 'success') if(defined $token); + $sth->finish(); + closedb($dbh); - return ('', 'ERROR', "user '" . $username . "' not known by rivendell") + unless(defined $token) { + return ('', 'ERROR', "user '" . $username . "' not known by rivendell") + } + return ($token, 'OK', 'success'); } return 1; |