Repository navigation
Fix FOUND_ROWS() without SQL_CALC_FOUND_ROWS - #533
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
After a SELECT without SQL_CALC_FOUND_ROWS or after a SHOW statement, FOUND_ROWS() counts the rows of the previous query. The count was read with fetchColumn()[0], which takes the first character of a stringified count, so FOUND_ROWS() returned "1" for 12 rows. Without stringified fetches, indexing the integer count returned null, and the result was 0. Use the fetched count directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fold the separate above-nine test into testFoundRowsWithoutSqlCalcFoundRows. The SELECT and SHOW TABLES checks now return 12 and 11 rows, which covers both the query and the query-with-params paths. The test no longer counts the setUp fixture tables, as the existing test drops them. Run the test with stringified fetches on and off. Without stringification, the old code returned 0 and emitted a warning.
d56c4a1 to
3bed95e
Compare
|
Thanks again, @Nandan108! Good catch, and a clean fix. I rebased the branch on trunk and made a few small changes to the tests. |
FOUND_ROWS() for more than nine rows without SQL_CALC_FOUND_ROWS
FOUND_ROWS() for more than nine rows without SQL_CALC_FOUND_ROWSFOUND_ROWS() without SQL_CALC_FOUND_ROWS
Summary
After a
SELECTwithoutSQL_CALC_FOUND_ROWS, or after aSHOWstatement,FOUND_ROWS()returns only the first digit of the row count:The count of the previous query is read with
fetchColumn()[0], which takes the first character of a stringified count. Without stringified fetches, indexing the integer count returnsnull, so the result is0and PHP emits a warning.SELECT SQL_CALC_FOUND_ROWS ...is not affected; it uses a different path.Fix
The fetched count is used directly.
Tests
testFoundRowsWithoutSqlCalcFoundRowsAboveNinechecksFOUND_ROWS()after a 12-rowSELECTand afterSHOW TABLESwith 13 tables, which covers both code paths. Each assertion fails ontrunk. The existingtestFoundRowsWithoutSqlCalcFoundRowsonly uses counts below ten.packages/mysql-on-sqlite: 1044 tests pass (PHP 8.3, SQLite 3.45.1); PHPCS is clean.Use of AI
This change was prepared with Claude Code (Claude Opus 5.5). I reviewed the code, the tests, and this description, and I take responsibility for the change.
🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
FOUND_ROWS()results for queries returning counts above nine, including when the database returns fetched values as strings.Tests
SELECTqueries and metadata commands, includingSHOW TABLESwith multiple tables. Verified results with both database fetch settings.