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

Add PHPDoc about boolean values in scalar() and queryScalar() #918

Merged
merged 1 commit into from
Jan 12, 2025

Conversation

Tigrov
Copy link
Member

@Tigrov Tigrov commented Jan 9, 2025

Q A
Is bugfix?
New feature?
Breaks BC?
Fixed issues #851

@Tigrov Tigrov requested a review from a team January 9, 2025 10:53
Copy link

codecov bot commented Jan 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.70%. Comparing base (98eed39) to head (1cfe760).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #918   +/-   ##
=========================================
  Coverage     99.70%   99.70%           
  Complexity     1498     1498           
=========================================
  Files            81       81           
  Lines          3702     3702           
=========================================
  Hits           3691     3691           
  Misses           11       11           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@vjik vjik left a comment

Choose a reason for hiding this comment

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

Suggest to add scalar $default = null parameter. This allow to use this methods for boolean values also.

@Tigrov
Copy link
Member Author

Tigrov commented Jan 9, 2025

How to use it?

Field of boolean type can return true, false and null values.

@vjik
Copy link
Member

vjik commented Jan 9, 2025

How to use it?

Field of boolean type can return true, false and null values.

When I know that result bool|null, I can use ->queryScalar('') code. When returns empty string - value doesn't exist.

@Tigrov
Copy link
Member Author

Tigrov commented Jan 11, 2025

Good idea, but it uses PDOStatement::fetchColumn() and the method returns false for both: no results and false value result

} elseif ($this->is($queryMode, self::QUERY_MODE_SCALAR)) {
/** @psalm-var mixed $result */
$result = $this->pdoStatement?->fetchColumn();

From the documentation https://www.php.net/manual/en/pdostatement.fetchcolumn.php

Note:
PDOStatement::fetchColumn() should not be used to retrieve boolean columns, as it is impossible to distinguish a value of false from there being no more rows to retrieve. Use PDOStatement::fetch() instead.

@vjik
Copy link
Member

vjik commented Jan 12, 2025

Good idea, but it uses PDOStatement::fetchColumn() and the method returns false for both: no results and false value result

So in this case my suggestion doesn't matter.

@Tigrov Tigrov merged commit 30aca10 into master Jan 12, 2025
57 checks passed
@Tigrov Tigrov deleted the add-doc-about-boolean branch January 12, 2025 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants