sidorares / sidorares/node-mysql2
Where in list prepared statement only returns first of list
Open
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 4.4k
- Forks
- 680
- Avg merge
- 9h 7m
- Merged PRs (30d)
- 59
Description
I have the following code. req.query.tags is a string of ids seperated by a comma, e.g. 1,2,3.
const query =
'SELECT DISTINCT images.* FROM images LEFT JOIN images_has_tags ON image_id = images.id WHERE tag_id IN (?)';
const [rows] = await conn.query(query, [req.query.tags]);
This returns only one row, this row matches the first item in the list.
(If req.query.tags is 1,2,3, the query equals ...WHERE tag_id = 1)
Whereas
const query =
'SELECT DISTINCT images.* FROM images LEFT JOIN images_has_tags ON image_id = images.id WHERE tag_id IN (1,2,3)';
const [rows] = await conn.query(query);
works fine.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the conn.query call shown in the report and trace how its parameter array is handled for the IN (?) placeholder. Reproduce the behavior with tags=1,2,3 and compare it with the working literal query. Done means the intended handling is clarified through a tested driver behavior or documented usage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql, nodejs, typescript
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100