Issues

ZF-2953: Zend_Db_Table_Abstract->insert returns empty value

Description

The "insert" method from "Zend_Db_Table_Abstract" (extended for MySql) doesn't return the value of the "most recent ID" when it receives an empty value ('') for this primary key. The register is properly inserted in the db.

It checks if the value is null:


        /**
         * If the primary key can be generated automatically, and no value was
         * specified in the user-supplied data, then omit it from the tuple.
         */
        if (array_key_exists($pkIdentity, $data) && $data[$pkIdentity] === null) {
            unset($data[$pkIdentity]);
        }

Maybe, it should check if the value is "empty".

Comments

Please categorize/fix as needed.

Fix Version Priority: Must Have ?

No action on this issue for too long. I'm reassigning to Ralph for re-evaluation and categorization.

Are you saying that


if (array_key_exists($pkIdentity, $data) && $data[$pkIdentity] === null) {

should become:


if (array_key_exists($pkIdentity, $data) && $data[$pkIdentity] == null) {
OR
if (array_key_exists($pkIdentity, $data) && $data[$pkIdentity] == '') {

?

Maybe, you could use the "empty" function...

I confirm this bug, still alive in ZF 1.7.4, also confirm that the "empty instead of null" check works for me. It's frustrating to see such a simple issue being carried over between releases for so long.

Fix version bumped up to 1.7.5. ZF 1.7.5 is released. The bug is still there.

Fix version bumped up to 1.7.6. ZF 1.7.6 is released. The bug is still there.

I don't wanna be a whiner, but am I missing something here? It's such an easy fix (just one line of code!) and it's so annoying to have to fix it over and over with each ZF release. Why is it getting so little attention?

I didn't take the time for a deeper check, but I believe these two issues are related, if not the same.

Maybe, I'll become a contributor to solve this "line of code"...

Actually using the function empty would cause unpredicted results. The value of '0' is valid in the auto-incrementing sequence therefore this would not be an adequate fix. Although the correct fix would be to utilize strlen. Will work on writing the patch and the test case for this in the next day or so.

Attached patch and test case for the issue.

Almost 3 years later, the issue is still open... solve it or close it, please! It's only one line of code!!!

Plus, everytime a new release is out we have to patch it to fix this issue. Annoying to say the least!

I've added a fix for this issue in r23621 in trunk.

Please test your applications against this. The fix does not use empty() or any other type in-specific routines to determine if a PK was included. Instead, it uses a smaller subset of valid primary key value types. For example, '0' and 0 are valid primary keys that would not pass an empty() test.

If this works for everyone, I will merge to 1.11.

-ralph

Resolved in trunk at r23621 and in branch 1.11 at 23657