Bug #21607 cached statement handles not released
Submitted: 13 Aug 2006 4:05 Modified: 7 Sep 2006 15:07
Reporter: Kolbe Kegel Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connectors: DBD::mysql ( Perl ) Severity:S3 (Non-critical)
Version:3.0006_1 OS:Linux (Linux)
Assigned to: Bugs System CPU Architecture:Any
Tags: dbd::mysql dbi perl prepared statement handle cached finish

[13 Aug 2006 4:05] Kolbe Kegel
Description:
Statement handles obtained using prepare_cached are not properly cleaned up when all of the results have been fetched from the handle.

According to DBI documentation:

When all the data has been fetched from a "SELECT" statement, the driver should automatically call "finish" for you. So you should not normally need to call it explicitly except when you know that you’ve not fetched all the data from a statement handle.  The most common example is when you only want to fetch one row, but in that case the "selectrow_*" methods are usually better anyway.  Adding calls to "finish" after each fetch loop is a common mistake, don’t do it, it can mask genuine problems like uncaught fetch errors.

How to repeat:
my ($stmt,$sth,$r);

$stmt = 'show variables';
$sth = $dbh->prepare_cached($stmt);
$sth->execute();

$r = $sth->fetchall_arrayref;

$sth = $dbh->prepare_cached($stmt);

Generates the following warning:

prepare_cached(show variables) statement handle DBI::st=HASH(0x8dbc10) still Active at sth_finish.pl line 21

Suggested fix:
"finish" should be called for cached prepared statement handles after all results have been fetched.
[7 Sep 2006 15:07] Patrick Galbraith
duplicate of 19874, which the fix for will be released this week
[17 Sep 2006 22:59] Arjen Lentz
Patrick, that reference is wrong, please note the currect bug#.