sidorares / sidorares/node-mysql2

Comments with a single apostrophe in queries with parameters raise a syntax error

Open
#707 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
4.4k
Forks
680
Avg merge
9h 7m
Merged PRs (30d)
59

Description

The error raised is:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':id' at line {insert_line_here}

🔴 Failing Case 1
Simple example

SELECT id
FROM users
WHERE
-- This comment with a single ' will break the parameter below it
id = :id;

🔴 Failing Case 2
Adding additional elements to the query does not affect it

SELECT id
FROM users
WHERE
username = "you" AND
-- This comment with a single ' will break the parameter below it
id = :id;

🔴 Failing Case 3
The minimum example

SELECT id
FROM users
WHERE
-- '
id = :id;

🔴 Failing Case 4
The quote does not need to be right before the parameter

-- '
SELECT id
FROM users
WHERE
id = :id;

💚 Passing Case 1
Replace parameter with a literal value

SELECT id
FROM users
WHERE
-- '
id = 1;

💚 Passing Case 2
Close the single quote

SELECT id
FROM users
WHERE
-- ''
id = :id;

💚 Passing Case 3
Move the quote after the parameter

SELECT id
FROM users
WHERE
id = :id;
-- '

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source files or tests are named in the issue. Start by reproducing the parameterized queries shown in the report and trace how SQL comments and named parameters are processed. Done means a single apostrophe in a comment no longer causes a syntax error while the listed passing and failing cases behave as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, typescript
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.