Subject: | selectrow_array fails if mysql_server_prepare is enabled |
Originally reported by Philip Stoev at
http://bugs.mysql.com/bug.php?id=27046
Description:
It appears that if selectrow_array() is used with mysql_server_prepare,
then the prepared statement remains at the server and a repeated query
will very soon reach the maximum number of prepared statements, causing
the script to fail.
How to repeat:
use DBI;
my $dbh = DBI->connect('dbi:mysql:mysql_server_prepare=1');
while (1) {
$dbh->selectrow_array("SELECT 1");
}
Will run for a while and then start failing with:
*DBD::mysql::db selectrow_array failed: Can't create more than
max_prepared_stmt_count statements (current value: 16382)
Suggested fix:
Make sure selectrow_array and the related calls removes any prepared
statements before completing. do() does not appear to be affected.
I can not see any mysql_stmt_close() in the DBD::mysql code. Maybe that
is why the statement does not get freed?
[3 May 2007 11:01] Mika Raento
The following patch does fix the leak from a simple testcase and passes
all test from 'make test'. Somebody with a better understanding of how
the lifetime of DBD objects works should review it. This is against 4.004.
<pre>
Index: dbdimp.c
===================================================================
--- dbdimp.c (revision 5029)
+++ dbdimp.c (revision 5030)
@@ -3783,6 +3783,8 @@
mysql_st_free_result_sets(sth, imp_sth);
}
DBIc_ACTIVE_off(imp_sth);
+ if (imp_sth->stmt) mysql_stmt_close(imp_sth->stmt);
+ imp_sth->stmt=0;
if (dbis->debug >= 2)
{
PerlIO_printf(DBILOGFP, "\n<-- dbd_st_finish\n");
</pre>