Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReferenceException when executing stored procedure with enum as parameter #812

Closed
EkoPratomo opened this issue May 6, 2020 · 1 comment
Assignees
Labels

Comments

@EkoPratomo
Copy link

EkoPratomo commented May 6, 2020

NullReferenceException when executing stored procedure with enum as parameter.
Happens on version 0.65 and 0.57. It was fine on version 0.56.

CREATE PROCEDURE `proced`(IN input enum ('One', 'Two', 'Three'))
...
command.CommandText = "proced";
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new MySqlParameter("input", "One"));
using(DbDataReader reader = await command.ExecuteReaderAsync()){}
...

I tried changing the parameter to varchar and it worked on all three versions.

CREATE PROCEDURE `proced`(IN input varchar(30))
...

Here's stack trace for version 0.65

System.NullReferenceException: Object reference not set to an instance of an object.
   at MySqlConnector.Core.TypeMapper.GetMySqlDbType(String typeName, Boolean unsigned, Int32 length) in /_/src/MySqlConnector/Core/TypeMapper.cs:line 169
   at MySqlConnector.Core.CachedParameter..ctor(Int32 ordinalPosition, String mode, String name, String dataType, Boolean unsigned, Int32 length) in /_/src/MySqlConnector/Core/CachedParameter.cs:line 21
   at MySqlConnector.Core.CachedProcedure.FillAsync(IOBehavior ioBehavior, MySqlConnection connection, String schema, String component, CancellationToken cancellationToken)
   at MySql.Data.MySqlClient.MySqlConnection.GetCachedProcedure(String name, Boolean revalidateMissing, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/MySql.Data.MySqlClient/MySqlConnection.cs:line 550
   at MySqlConnector.Core.CommandExecutor.ExecuteReaderAsync(IReadOnlyList`1 commands, ICommandPayloadCreator payloadCreator, CommandBehavior behavior, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/CommandExecutor.cs:line 39

==== Edit 1 ====
After digging in the source code, i found that CachedProcedure.FillAsync is no longer using DATA_TYPE column from information_schema.parameters, instead it parses the dataType from DTD_IDENTIFIER column. That should be fine, but the parser doesn't seem to handle enum.
DTD_IDENTIFIER value for enum parameter should look like this enum('YES','NO').

@bgrainger bgrainger self-assigned this May 7, 2020
@bgrainger bgrainger added the bug label May 7, 2020
@bgrainger
Copy link
Member

Fixed in 0.66.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants