Repository navigation
Commit 3e75ae0
authored
Fix duplicate column names in MySQL proxy results (#628)
## What?
Closes #627
Fixes an issue where the MySQL proxy returns incorrect values when a
query has columns with the same name.
For example:
```sql
SELECT 1 AS x, 2 AS x;
```
MySQL returns `1, 2`, but the proxy returns `2, 2`. This also affects
joins with columns that have the same name.
## Why?
`SQLite_Adapter::handle_query()` used `PDO::FETCH_OBJ`, which overwrites
values when column names are the same.
`MySQL_Protocol::build_row_packet()` then reads values by column name,
causing both columns to return the same value.
## How?
- Changed `SQLite_Adapter` to use `PDO::FETCH_NUM`.
- Updated `MySQL_Protocol::build_row_packet()` to read values by column
position instead of name.
- Updated the method to accept `array $row` instead of `object $row`.
Direct callers must now pass numeric arrays.
- Added regression tests for duplicate column names and null values.
- Updated existing test mocks to use arrays.
## Use of AI Tools
**AI assistance:** Yes
**Tool:** Codex
**Used for:** Investigating the issue, implementing the fix, adding
tests, and drafting the PR description. I manually reviewed and verified
the changes.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
## Summary by CodeRabbit
* **Bug Fixes**
* Query results now preserve separate values when multiple columns share
the same name, including columns returned from joined queries.
* SQL `NULL` values are returned as `null` instead of being confused
with other values.
* Large query results continue to return blob values correctly.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->1 parent 3dd5b35 commit 3e75ae0
4 files changed
Lines changed: 20 additions & 6 deletions
File tree
- packages/mysql-proxy
- src
- Adapter
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
501 | 501 | | |
502 | 502 | | |
503 | 503 | | |
504 | | - | |
| 504 | + | |
505 | 505 | | |
506 | 506 | | |
507 | | - | |
| 507 | + | |
508 | 508 | | |
509 | | - | |
510 | | - | |
| 509 | + | |
| 510 | + | |
511 | 511 | | |
512 | 512 | | |
513 | 513 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
163 | | - | |
| 163 | + | |
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
50 | 64 | | |
51 | 65 | | |
52 | 66 | | |
| |||
0 commit comments