Repository navigation
Commit 81d6afa
Fix FOUND_ROWS() for more than nine rows without SQL_CALC_FOUND_ROWS (#533)
## Summary
After a `SELECT` without `SQL_CALC_FOUND_ROWS`, or after a `SHOW`
statement, `FOUND_ROWS()` returns only the first digit of the row count:
```sql
-- Table "t" has 25 rows.
SELECT id FROM t;
SELECT FOUND_ROWS();
-- '2' (MySQL: 25)
```
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 returns `null`, so the result is `0`
and 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
`testFoundRowsWithoutSqlCalcFoundRowsAboveNine` checks `FOUND_ROWS()`
after a 12-row `SELECT` and after `SHOW TABLES` with 13 tables, which
covers both code paths. Each assertion fails on `trunk`. The existing
`testFoundRowsWithoutSqlCalcFoundRows` only 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](https://claude.com/claude-code)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Corrected `FOUND_ROWS()` results for queries returning counts above
nine, including when the database returns fetched values as strings.
* **Tests**
* Expanded coverage for row counts from unrestricted `SELECT` queries
and metadata commands, including `SHOW TABLES` with multiple tables.
Verified results with both database fetch settings.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Jan Jakeš <jan@jakes.pro>1 parent ba9d450 commit 81d6afa
2 files changed
Lines changed: 27 additions & 19 deletions
File tree
- packages/mysql-on-sqlite
- src/sqlite
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5169 | 5169 | | |
5170 | 5170 | | |
5171 | 5171 | | |
5172 | | - | |
| 5172 | + | |
5173 | 5173 | | |
5174 | 5174 | | |
5175 | 5175 | | |
5176 | 5176 | | |
5177 | | - | |
| 5177 | + | |
5178 | 5178 | | |
5179 | 5179 | | |
5180 | 5180 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4186 | 4186 | | |
4187 | 4187 | | |
4188 | 4188 | | |
4189 | | - | |
| 4189 | + | |
| 4190 | + | |
| 4191 | + | |
| 4192 | + | |
| 4193 | + | |
| 4194 | + | |
4190 | 4195 | | |
4191 | 4196 | | |
4192 | 4197 | | |
4193 | 4198 | | |
4194 | 4199 | | |
4195 | 4200 | | |
4196 | | - | |
| 4201 | + | |
4197 | 4202 | | |
4198 | 4203 | | |
4199 | | - | |
| 4204 | + | |
4200 | 4205 | | |
4201 | | - | |
| 4206 | + | |
4202 | 4207 | | |
4203 | 4208 | | |
4204 | 4209 | | |
4205 | 4210 | | |
4206 | | - | |
| 4211 | + | |
4207 | 4212 | | |
4208 | 4213 | | |
4209 | 4214 | | |
4210 | 4215 | | |
4211 | | - | |
| 4216 | + | |
4212 | 4217 | | |
4213 | 4218 | | |
4214 | 4219 | | |
4215 | 4220 | | |
4216 | | - | |
| 4221 | + | |
4217 | 4222 | | |
4218 | 4223 | | |
4219 | 4224 | | |
4220 | 4225 | | |
4221 | | - | |
| 4226 | + | |
4222 | 4227 | | |
4223 | 4228 | | |
4224 | 4229 | | |
4225 | 4230 | | |
4226 | | - | |
| 4231 | + | |
4227 | 4232 | | |
4228 | 4233 | | |
4229 | 4234 | | |
4230 | 4235 | | |
4231 | | - | |
| 4236 | + | |
4232 | 4237 | | |
4233 | 4238 | | |
4234 | 4239 | | |
4235 | 4240 | | |
4236 | | - | |
| 4241 | + | |
4237 | 4242 | | |
4238 | 4243 | | |
4239 | 4244 | | |
4240 | 4245 | | |
4241 | | - | |
| 4246 | + | |
4242 | 4247 | | |
4243 | 4248 | | |
4244 | 4249 | | |
4245 | 4250 | | |
4246 | | - | |
| 4251 | + | |
4247 | 4252 | | |
4248 | 4253 | | |
4249 | 4254 | | |
4250 | 4255 | | |
4251 | | - | |
| 4256 | + | |
4252 | 4257 | | |
4253 | | - | |
| 4258 | + | |
| 4259 | + | |
| 4260 | + | |
| 4261 | + | |
4254 | 4262 | | |
4255 | 4263 | | |
4256 | | - | |
| 4264 | + | |
4257 | 4265 | | |
4258 | 4266 | | |
4259 | 4267 | | |
4260 | 4268 | | |
4261 | | - | |
| 4269 | + | |
4262 | 4270 | | |
4263 | 4271 | | |
4264 | 4272 | | |
| |||
0 commit comments