diff --git a/lib/commands/get.pm b/lib/commands/get.pm index 4eda4a3e54a52ffe45fb7946897c2d137132ffb0..b5fefec35bf8ae48f066c472b93cb6079ad9b6ce 100644 --- a/lib/commands/get.pm +++ b/lib/commands/get.pm @@ -8,11 +8,11 @@ use lib "$FindBin::Bin/lib/"; use utils::print; use utils::db; -our $dbh; our $irc; our $log; my $last_req; +my $dbh; my $sth; sub exec { @@ -30,7 +30,14 @@ sub exec { my @words = ($msg =~ /(?:^| )([^#\s]+)/g); if (not defined $last_req or $msg ne $last_req) { - my $dbh = utils::db::get_new_session; + # we close a previous session if needed + if ($dbh) { + $sth->finish if $sth->{'Active'}; + $dbh->commit; + $dbh->disconnect; + } + + $dbh = utils::db::get_new_session; my @words_param; foreach (@words) { @@ -129,7 +136,7 @@ sub exec { # this is specific to the mysql driver $rows = $sth->rows; - my $sth2 = utils::db::get_new_session()->prepare("select tag + my $sth2 = utils::db::main_session()->prepare("select tag from playbot_tags where id = ? "); @@ -157,7 +164,7 @@ sub exec { $irc->yield(privmsg => $chan => $irc_msg); # we save the get like a post - $sth2 = utils::db::get_new_session()->prepare_cached(' + $sth2 = utils::db::main_session()->prepare_cached(' INSERT INTO playbot_chan (content, chan, sender_irc) VALUES (?,?,?)'); $log->error("Couldn't prepare querie; aborting") unless (defined $sth2); diff --git a/lib/commands/parser.pm b/lib/commands/parser.pm index 11be3d9d0c11080637ed0c7bb261b5f4a48b81fc..66db81986c4b47ddefe554869efbb3905ae39a50 100644 --- a/lib/commands/parser.pm +++ b/lib/commands/parser.pm @@ -21,7 +21,6 @@ sub setConf { $commands::fav::dbh = $dbhNew; $commands::tag::dbh = $dbhNew; - $commands::get::dbh = $dbhNew; $commands::later::dbh = $dbhNew; $utils::id::dbh = $dbhNew;