Issues

ZF-5663: Statement doesn't get deallocated after preparation and execution

Issue Type: Bug Created: 2009-01-30T16:03:08.000+0000 Last Updated: 2012-11-20T20:52:43.000+0000 Status: Closed Fix version(s): Reporter: Mathias Seiler (broedel.org) Assignee: None Tags: - Zend_Db

Related issues: Attachments:

Description

Hello

In a relatively large transaction using Zend_Db_Adapter_Pdo_Pgsql the PostgreSQL Database suddenly (and somewhat randomly) terminates this transaction with the error:

ERROR: 42P05: prepared statement "pdo_pgsql_stmt_0a0d3ba8" already exists

Based on a quick look at "prepare.c" (in the PostgreSQL source code), the presence of the prepared statement is checked by its name and not its post-parse-analysis tree. I assume the name is set by PDO and is in this special case "pdo_pgsql_stmt_0a0d3ba8". Please correct me if I'm wrong.

I think the problem relies in Zend/Db/Adapter/Abstract.php, e.g.

<pre class="highlight">
        $stmt = $this->query($sql, $bind);
        $result = $stmt->fetchAll($fetchMode);
        return $result;

Here this $stmt is not cleared after execution and in the case of a large transaction the statement relies in a prepared state in the database. I think this sometimes gets garbage collected by php, but as it seems not at the right time. In a method like "fetchAll(...)" or "fetchOne(...)" or similar "one-shot" methods, this statement can't be reused. In this case a prepared statement doesn't make sense, but this is discussed in another report already.

Isn't it a bad idea not to close a resource which isn't reused later in the code?

Either I'm totally wrong and royally fucked up my database or this is really a problem with Zend_Db_Adapter_Pdo_Pgsql and/or PDO. But I think not closing a resource which is not used in the later process is bad practice and should be fixed.

Could someone shed a little more light on this? This would be great :)

PostgreSQL Version:

<pre class="highlight">
SELECT version();
                                          version                                           
--------------------------------------------------------------------------------------------
 PostgreSQL 8.3.5 on i486-pc-linux-gnu, compiled by GCC gcc-4.3.real (Debian 4.3.2-1) 4.3.2
(1 row)

Please tell me if you need more information about this problem (exact statements, php version, phpinfo() ...). Thx.

Comments

Posted by Rob Allen (rob) on 2012-11-20T20:52:43.000+0000

Bulk change of all issues last updated before 1st January 2010 as "Won't Fix".

Feel free to re-open and provide a patch if you want to fix this issue.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts