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

[DBAL-1028] Fix fetching NULL values via fetchColumn() #709

Merged
merged 2 commits into from
Nov 5, 2014

Conversation

deeky666
Copy link
Member

PDO drivers return null when retrieving a SQL NULL value from a column via Statement::fetchColumn().
However all native driver implementations except mysqli return false which according to the interface should only be returned if no more rows are available or an error occurred. So currently it is not possible to retrieve a SQL NULL value via Statement::fetchColumn() with those drivers.
This PR fixes this. Additionally if a non-existing column index is requested from the resultset, PDO also returns null whereas those mentioned native drivers return false. This is also fixed.

@doctrinebot
Copy link

Hello,

thank you for creating this pull request. I have automatically opened an issue
on our Jira Bug Tracker for you. See the issue link:

http://www.doctrine-project.org/jira/browse/DBAL-1028

We use Jira to track the state of pull requests and the versions they got
included in.

@Ocramius Ocramius self-assigned this Nov 5, 2014
}

return false;
return isset($row[$columnIndex]) || array_key_exists($columnIndex, $row) ? $row[$columnIndex] : null;
Copy link
Member

Choose a reason for hiding this comment

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

You can actually skip array_key_exists() here, as the return value will be null anyway

Ocramius added a commit that referenced this pull request Nov 5, 2014
[DBAL-1028] Fix fetching NULL values via fetchColumn()
@Ocramius Ocramius merged commit 0b3e004 into doctrine:master Nov 5, 2014
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants