Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getOne() produces a warning if the query returns no results. #34

Open
borb opened this issue Nov 17, 2016 · 2 comments
Open

getOne() produces a warning if the query returns no results. #34

borb opened this issue Nov 17, 2016 · 2 comments

Comments

@borb
Copy link
Contributor

borb commented Nov 17, 2016

getOne() calls fetchInto() with an initialised $row containing null. If the query returns no results, $row is never populated with an array of results, and getOne() returns $row[0], which is both an array operation on something that isn't an array, and also an undefined value. In all cases, null is returned as the result of getOne(), even if the field contains null.

We can't fix the logic of returning null, but we can fix the invalid array access by checking if $row is_array() and $row[0] isset() before returning.

@ghost
Copy link

ghost commented Jan 26, 2017

This is brilliantly complicated, much more than I had previously considered.

At the moment, this evades testing because when writing the stub driver for the unit tests, we wrote a perfect-world scenario which included checks to ensure we didn't send any more data when fetching a non-existant row.

We will have to look at the stub driver architecture to ensure that we reproduce what the real drivers actually do in order to validate that we can test this with real world scenarios.

@ghost ghost added this to the 0.3.1 milestone Jan 27, 2017
@ghost ghost self-assigned this Jan 30, 2017
@ghost ghost added testsuite bug labels Jan 30, 2017
@ghost ghost removed this from the 0.3.1 milestone Jan 30, 2017
@ghost ghost removed the testsuite label Jan 30, 2017
@ghost
Copy link

ghost commented Jan 30, 2017

This is not the bug we previously thought it was, and this bug definitely originates in PEAR DB beforehand.

The older DB_mysql driver, and reproduced in the PdoDriver, checks the result of the fetch from the database. The older driver did not consider that the result could be '0', and thus if you fetch from '0' the database, it will return 'null' in the getOne() call, which is annoying and should be fixed.

However, mysql_fetch_row would return false for no row, so we should fix the PdoDriver and DoctrineDbal drivers to correctly check the returned data so that we can legitimately send '0' back verbatim to the caller, and handle situations where there is no data to be returned (possibly returning null, possibly returning an Error instance with the correct error constant).

But I am taking this off of the 0.3.1 milestone because this is a pre-existing bug and thus is expected behaviour.

@ghost ghost added legacy bug and removed bug labels Jan 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant