DapperLib / DapperLib/DapperAOT

in clause of mysql caused exception

Open
#110 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
472
Forks
43
Avg merge
1d 4h
Merged PRs (30d)
18

Description

Describe the bug

wherer in clause of mysql caused exception

Where are you seeing this?

  • what Dapper/Dapper.StrongName version?
    Dapper Version="2.1.24"
  • what Dapper.AOT/Dapper.Advisor version?
    Dapper.AOT Version="1.0.31"
  • if relevant: what database backend?
    MySqlConnector Version="2.3.1"
    MySQL 8.2.0
  • dotnet version
    8.0.100

To Reproduce

await using var connection = new MySqlConnection(connectionString);
long[] longs = [1, 2, 3];

var comments = await connection.QueryAsync<Comment>(
    "SELECT * FROM comments WHERE id in @ids", new { ids = longs });

if aot is not enabled, is works well.
however, with aot enabled, it doesn't work.

Unhandled exception. System.NotSupportedException: Parameter type Int64[] is not supported; see https://fl.vu/mysql-param-type. Value: System.Int64[]
   at MySqlConnector.MySqlParameter.AppendSqlString(ByteBufferWriter writer, StatementPreparerOptions options) in /_/src/MySqlConnector/MySqlParameter.cs:line 559
   at MySqlConnector.Core.StatementPreparer.ParameterSqlParser.DoAppendParameter(Int32 parameterIndex, Int32 textIndex, Int32 textLength) in /_/src/MySqlConnector/Core/StatementPreparer.cs:line 77
   at MySqlConnector.Core.StatementPreparer.ParameterSqlParser.OnNamedParameter(Int32 index, Int32 length) in /_/src/MySqlConnector/Core/StatementPreparer.cs:line 65
   at MySqlConnector.Core.SqlParser.Parse(String sql) in /_/src/MySqlConnector/Core/SqlParser.cs:line 266
   at MySqlConnector.Core.StatementPreparer.ParseAndBindParameters(ByteBufferWriter writer) in /_/src/MySqlConnector/Core/StatementPreparer.cs:line 32
   at MySqlConnector.Core.SingleCommandPayloadCreator.WriteCommand(IMySqlCommand command, ByteBufferWriter writer, Boolean appendSemicolon, Boolean isFirstCommand, Boolean isLastCommand) in /_/src/MySqlConnector/Core/SingleCommandPayloadCreator.cs:line 266
   at MySqlConnector.Core.SingleCommandPayloadCreator.WriteQueryPayload(IMySqlCommand command, IDictionary`2 cachedProcedures, ByteBufferWriter writer, Boolean appendSemicolon, Boolean isFirstCommand, Boolean isLastCommand) in /_/src/MySqlConnector/Core/SingleCommandPayloadCreator.cs:line 77
   at MySqlConnector.Core.SingleCommandPayloadCreator.WriteQueryCommand(CommandListPosition& commandListPosition, IDictionary`2 cachedProcedures, ByteBufferWriter writer, Boolean appendSemicolon) in /_/src/MySqlConnector/Core/SingleCommandPayloadCreator.cs:line 45
   at MySqlConnector.Core.CommandExecutor.ExecuteReaderAsync(CommandListPosition commandListPosition, ICommandPayloadCreator payloadCreator, CommandBehavior behavior, Activity activity, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/CommandExecutor.cs:line 44
   at MySqlConnector.MySqlCommand.ExecuteReaderAsync(CommandBehavior behavior, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlCommand.cs:line 357
   at MySqlConnector.MySqlCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlCommand.cs:line 350

it seems like that the sql string when using aot is like

SELECT id, .... FROM comments WHERE id in ?

rather than

SELECT id, .... FROM comments WHERE id in (?, ?, ?)

Expected behavior

in clause of mysql works well like not using aot.

Contributor guide

No contributing guide indexed for this repository

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

Start at the QueryAsync call with the MySqlConnection and compare the SQL and parameters produced with AOT enabled versus disabled. Reproduce it against MySQL 8.2 using the provided long[] ids and inspect the MySqlConnector parameter error. Done means the IN clause works with AOT as it does without AOT.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, mysql
Domain
databases
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.