DapperLib / DapperAOT

Build time tools in the flavor of Dapper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

in clause of mysql caused exception

sixwaaaay opened this issue · comments

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.

Having the same issue for SQLConnector. Any workaround or fix?