Why are all those constants null? Parsing the error message is what this leads to and that is a pretty expensive operation. E.g. I rely on constraints set in the DB (table) on some insert operations and would like to disregard some "errors" returned. Impossible if the error code is NULL.

At least you could pass through the real error codes which the designated backend provides and allow people to match based on that. I am using Zend_Db (with PDO mysql).

I remember I had an issue open about a year or maybe 1.5 years ago describing exactly the same issues. I thought it had been fixed before.

It's only an improvement, but also a major showstopper for me.

Comments

Posted by Till Klampaeckel (till) on 2008-11-06T21:19:14.000+0000

Just adding the relation.

Posted by Till Klampaeckel (till) on 2010-08-24T15:54:36.000+0000

Hey Ralph,

can you comment what the hold up is?

I'd love to help if I know how. Otherwise the fix seems trivial, e.g.:

The constants are null because it seems they were generated from the constants defined by the PHP PDO extension in source file php-src/ext/pdo/pdo_dbh.c. The constants were not defined as enums like the other PDO constants so their values were all set to null when defined at the PHP level.

Since they're all NULL, and I don't see them being referenced anywhere in the C source except for where they are defined (as null), these can probably be safely removed from Zend_Db. They appear to serve no purpose since it doesn't appear that PDO is using these constants, and if it were, you couldn't differentiate between them anyway since they are all NULL. Comments?

Patch is attached.

Posted by Marc Hodgins (mjh_ca) on 2010-11-19T11:49:07.000+0000

Patch applied to trunk in r23404, merged to 1.11 release branch in r23405

Till, is there a real use case where you find this has caused an actual BC break?

Per my earlier comments - they're all defined as NULL, just like in the underlying PDO driver. Therefore these constants cannot be used to differentiate between error conditions... they appear to serve no purpose at all either at the PDO driver level or at the Zend_Db level. I can't see how anyone is actually using these where their removal would cause a BC break.

This patch went in a number of versions ago and no one has raised any issues about this.

Posted by Till Klampaeckel (till) on 2011-08-21T21:59:20.000+0000

Hey Marc,

for some some reason, I don't see the constants at all though? They are not defined -- not even null.

That's my issue. I used them in my code, and now it fatals because the error constant is not there anymore.

My real use-case for 'values' of these constants was originally that parsing an error message is not very feasible. If I wanted to use PDO, I'd use it, but I use Zend_Db instead (and MySQLi). How do I tell errors apart? But using strstr, strpos or substr on the exception's message?

Does that make sense?

Till

Posted by Till Klampaeckel (till) on 2011-08-21T22:00:57.000+0000

I also mis-understood your original comment -- even if they are null, you cannot just remove them.

That's a clear BC break. Cause now they are not there and code like this will fatal:

<pre class="highlight">
if (Zend_Db::ERR_ALREADY_EXISTS) {
}

Posted by Marc Hodgins (mjh_ca) on 2011-08-23T00:33:04.000+0000

Hi Till, if you were using the removed ERR_ constants, your code was already (silently) failing or otherwise broken because these constants are all defined with the same value.

Yes, removing causes a BC break but it also fixes a 'bug' as these constants are NOT able to be used to differentiate error conditions and it is clearly misleading.

The ideal solution would be to assign values to these constants in Zend/Db.php as per the original bug description, however this won't work because of the underlying PDO extension defining these as NULL. Removing the constants alerts you to the fact that these constants should not be used as they won't behave as you expect.

Posted by Till Klampaeckel (till) on 2011-08-24T10:24:28.000+0000

Doesn't matter, it's a BC break. ZF doesn't do them in minor release for this just this reason: you break working code.

Posted by Pádraic Brady (padraic) on 2011-08-28T10:14:23.000+0000

Reverted removal of constants. BC breaks are not allowed in ZF1 unless for a critical or security issue where approval is agreed in advance with Zend.

I am additionally marking the issue as Won't Fix as the constants, while NULL, are nonetheless accurate for PDO as weird as it seems. Use at your own risk ;).