DapperLib / Dapper

Dapper - a simple object mapper for .Net
https://www.learndapper.com/
Other
17.46k stars 3.67k forks source link

MySql In operator throw syntax error #1618

Open vickyRathee opened 3 years ago

vickyRathee commented 3 years ago

Error - 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 ''[1]''

Code

public async Task<IEnumerable<User>> GetUsersAsync(long[] user_ids)
        {
            using MySqlConnection connection = new MySqlConnection(rdsConnection);

            const string sqlQuery = @"Select user_id, user_name From Users Where user_id in @Ids";

            var result = await connection.QueryAsync<User>(sqlQuery, new
            {
                Ids = user_ids
            });

            return result;
        }

Stack

MySql.Data.MySqlClient.MySqlException (0x80004005): 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 ''[1]'' at line 5
   at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
   at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
   at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int64& insertedId)
   at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
   at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Common.DbCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
--- End of stack trace from previous location ---
   at Dapper.SqlMapper.QueryAsync[T](IDbConnection cnn, Type effectiveType, CommandDefinition command) in /_/Dapper/SqlMapper.Async.cs:line 418

MySQL - 5.7.mysql_aurora.2.07.2

lucaxchaves commented 3 years ago

I'll take a look into this one!

vickyRathee commented 3 years ago

@lucaxchaves Thanks, let me know if you need any more details.

bgrainger commented 3 years ago

the right syntax to use near ''[1]'' at line 5

I'm not sure how this error would have been generated from the SQL that's shown. Is there a more full repro?

Also, I see you're using QueryAsync with MySql.Data, but it doesn't support async I/O. You can switch to MySqlConnector if you want true async support for MySQL.