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
## Release `3.1.1` Version bump and changelog update for release `3.1.1`. **Changelog draft:** * Support date arithmetic with `INTERVAL` operators ([#539](#539)) * Fix `ROLLBACK` as the first transaction of a connection ([#537](#537)) * Fix matching a foreign key reference to a unique key with a different case ([#534](#534)) * Fix `FOUND_ROWS()` without `SQL_CALC_FOUND_ROWS` ([#533](#533)) * Fix unique keys and foreign key restore without stringified fetches ([#532](#532)) * Fix `CREATE TEMPORARY TABLE IF NOT EXISTS` and `DROP TEMPORARY TABLE` as the first temporary table ([#524](#524)) * Fix a warning for a foreign key referencing a table with a shorter unique key ([#523](#523)) * Fix temporary table lookup without stringified fetches and with a different case ([#522](#522)) **Full changelog:** v3.1.0...release/v3.1.1 ## Next steps 1. **Review** the changes in this pull request. 2. **Push** any additional edits to this branch (`release/v3.1.1`). 3. **Merge** this pull request to complete the release. Merging will automatically build the plugin ZIP, create a [GitHub release](https://github.com/WordPress/sqlite-database-integration/releases), and deploy to [WordPress.org](https://wordpress.org/plugins/sqlite-database-integration/).
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.