Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Fixes #330 current NULL for mysqli #337

Closed

Conversation

ezimuel
Copy link
Contributor

@ezimuel ezimuel commented Aug 17, 2018

This PR fixes #330 and replaces #334. I focused the fix directly on mysqli adapter, and not anymore in the Zend\Db\ResultSet\AbstractResultSet::current(), changing the default $currentData value of Zend\Db\Adapter\Driver\Mysqli\ResultSet to NULL. I added an integration test to reproduce the issue, as reported in #330.

@ezimuel
Copy link
Contributor Author

ezimuel commented Aug 17, 2018

@bartmcleod I revert the change of #334, your commit 8276cf6#diff-86b3a79320eb564e46456a1b75003271R197 has been reinsert, now the solution is directly in the mysqli adapter.

@WillyBaldy
Copy link

Good work. I'm just wondering if ResultSet/AbstractResultSet-->current() should not at least enforce that the resulting value is null or an array, or else it would throw an exception? We use null in the method signature but we actually don't enforce it? Seems a bit fishy to me.

@WillyBaldy
Copy link

(The idea of a ResultSet and pretty much the whole Zend\Db is to abstract the driver you're using, so "programming errors" in some drivers should not lead to different result to the current() method on ResultSet)

@WillyBaldy
Copy link

The reason I'm picky on this is that there's literally hundreds of places in my code where I do if ($row === null) to know if it's empty after calling ResultSet-->current(), so I feel the bug could come back any time in the future and I would not have a clear explanation of the error, the code keeps on going. At least, an exception "The driver is returning an invalid value" or something like that would allow me to know right away it's an internal error to Zend\Db.

@ezimuel
Copy link
Contributor Author

ezimuel commented Aug 20, 2018

@willy0275 you right, there are some inconsistencies in these adapters return types. We can think to uniform everything and introduces Exceptions in ver. 3.0.0 since this will be a BC break.

@willy-opale
Copy link

Any schedule on this important bug fix? We're still using a private repo which is a copy of zend db 2.9 with a temporary fix in the source code.

@@ -51,9 +51,9 @@ class Result implements
protected $nextComplete = false;

/**
* @var bool
* @var mixed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have any stricter type that can be used here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be null or array, depending on the current() state. Moreover, I just reviewed all the adapter results and this is the scenario:

Adapter\Driver\Pgsql - current(): array|false
Adapter\Driver\Mysqli - current(): array|null
Adapter\Driver\Oci8 - current(): array|false
Adapter\Driver\Pdo - current(): array|object|false
Adapter\Driver\Sqlsrv - current(): array|false|null

I think we should try to normalize it. Maybe, we can throw an Exception if the adapter returns an error during the fetch process, and use null as empty value. Of course, this will be released with zend-db 3.0.0
@Ocramius and @willy0275 what do you think?

*/
protected $currentData = false;
protected $currentData = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a BC break for anything inheriting from this class. Sadly, the class is not final, so these changes land in future releases (develop)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is, 2.9 introduced a BC break from 2.8 because recent previous versions used to return null on empty result sets. I remember more than a year ago I was using false (even though signature said null) and it was "fixed" and I had to change all of my code to use null instead of false. So I think a BC break here from 2.9 would be acceptable to put things back to "normal". If not, I'll have to wait for 3.0 for a "simple" bug fix. I can't even go back to 2.8 because there are requirements that are not met with PHP 7.2.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'm planning it for zend-db 3.0.0. I'll point to develop, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to release this in 2.10.0 since it's a rollback of 2.8 behaviour.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! We are still on our local patched version of 2.9, so it's going to be great to be able to switch back to the main repo.


namespace ZendIntegrationTest\Db\Adapter\Driver\Mysqli;

trait TraitSetup
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's please not use traits for stashing out duplicated code: this is static code, and should be kept as such (static utility)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate why? Moreover, you mentioned this is static code?! Thanks.

@ezimuel ezimuel added this to the 3.0.0 milestone Dec 5, 2018
@ezimuel ezimuel modified the milestones: 3.0.0, 2.10.0 Feb 25, 2019
@ezimuel
Copy link
Contributor Author

ezimuel commented Feb 25, 2019

Merged in develop.

@ezimuel ezimuel closed this Feb 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Zend\Db\ResultSet\ResultSet->current() returns false instead of NULL
4 participants