Querying for empty list fails with MySQL Server 5.6
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
MySQL Server 5.6.29
Dapper 1.50.1
MySql.Data 6.9.9
Execute the following code (query adapted from https://github.com/StackExchange/dapper-dot-net#list-support):
var csb = new MySqlConnectionStringBuilder { Server = "localhost", UserID = "root", Password = "..." };
using (var connection = new MySqlConnection(csb.ConnectionString))
{
connection.Open();
connection.Query<int>("select * from (select 1 as Id) as X where Id in @Ids", new { Ids = new int[0] }).ToList();
}
It throws a MySqlException: "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 'WHERE 1 = 0)' at line 1".
For this statement, Dapper sets the CommandText to select * from (select 1 as Id) as X where Id in (SELECT @Ids WHERE 1 = 0)
The MySql.Data connector interpolates the command parameters and rewrites this as select * from (select 1 as Id) as X where Id in (SELECT NULL WHERE 1 = 0) before sending it to MySQL Server.
MySQL Server 5.6 rejects this as invalid SQL syntax.
Upgrading to MySQL Server 5.7.11 fixes the exception, but may not always be practical. For MySQL Server 5.6, the following query would be valid (and selects 0 rows): EDIT: deleted this suggested workaround because—although it selects zero rows—the inverse query select * from (select 1 as Id) as X where Id in (SELECT NULL).WHERE Id NOT IN (SELECT NULL) also selects zero rows when the intent is to select all rows.
Contributor guide
No contributing guide indexed for this repository
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 by running the provided C# reproduction against MySQL Server 5.6 and inspect Dapper's list-parameter expansion together with MySql.Data's parameter interpolation. No file or test is named in the issue, so locating the relevant implementation and regression-test area will require repository research. Done means empty-list queries no longer produce invalid MySQL 5.6 SQL while preserving correct NOT IN behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, mysql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100