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

Setting MySqlParameter.Value to a StringBuilder instance is not supported #975

Closed
appel1 opened this issue Apr 23, 2021 · 5 comments
Closed

Comments

@appel1
Copy link

appel1 commented Apr 23, 2021

Is this intentional? At least the Migrating from Connector/NET documentation should be updated to mention this, and other such breaking changes.

With Connector/NET this works.

StringBuilder sb = new StringBuilder();
sb.Append("foo");
command.Parameters.Add(new MySqlParameter { ParameterName = "ColumnName", Value = sb });

With MySqlConnector 1.3.3 it fails with this exception:

System.NotSupportedException: Parameter type StringBuilder is not supported; see https://fl.vu/mysql-param-type. Value: foo
   at MySqlConnector.MySqlParameter.AppendSqlString(ByteBufferWriter writer, StatementPreparerOptions options) in /_/src/MySqlConnector/MySqlParameter.cs:line 435
   at MySqlConnector.Core.StatementPreparer.ParameterSqlParser.DoAppendParameter(Int32 parameterIndex, Int32 textIndex, Int32 textLength) in /_/src/MySqlConnector/Core/StatementPreparer.cs:line 87
   at MySqlConnector.Core.StatementPreparer.ParameterSqlParser.OnNamedParameter(Int32 index, Int32 length) in /_/src/MySqlConnector/Core/StatementPreparer.cs:line 75
   at MySqlConnector.Core.SqlParser.Parse(String sql) in /_/src/MySqlConnector/Core/SqlParser.cs:line 198
   at MySqlConnector.Core.StatementPreparer.ParseAndBindParameters(ByteBufferWriter writer) in /_/src/MySqlConnector/Core/StatementPreparer.cs:line 37
   at MySqlConnector.Core.SingleCommandPayloadCreator.WriteCommand(IMySqlCommand command, ByteBufferWriter writer) in /_/src/MySqlConnector/Core/SingleCommandPayloadCreator.cs:line 206
   at MySqlConnector.Core.SingleCommandPayloadCreator.WriteQueryPayload(IMySqlCommand command, IDictionary`2 cachedProcedures, ByteBufferWriter writer) in /_/src/MySqlConnector/Core/SingleCommandPayloadCreator.cs:line 59
   at MySqlConnector.Core.SingleCommandPayloadCreator.WriteQueryCommand(CommandListPosition& commandListPosition, IDictionary`2 cachedProcedures, ByteBufferWriter writer) in /_/src/MySqlConnector/Core/SingleCommandPayloadCreator.cs:line 32
   at MySqlConnector.Core.CommandExecutor.ExecuteReaderAsync(IReadOnlyList`1 commands, ICommandPayloadCreator payloadCreator, CommandBehavior behavior, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/CommandExecutor.cs:line 49
   at MySqlConnector.MySqlCommand.ExecuteReaderAsync(CommandBehavior behavior, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlCommand.cs:line 314
   at MySqlConnector.MySqlCommand.ExecuteReader() in /_/src/MySqlConnector/MySqlCommand.cs:line 106
   at ConsoleApp12.Program.Main(String[] args) in C:\Users\johan\source\repos\ConsoleApp12\ConsoleApp12\Program.cs:line 23
@bgrainger
Copy link
Member

At least the Migrating from Connector/NET documentation should be updated to mention this, and other such breaking changes.

The documentation linked in the exception message does already cover this: https://fl.vu/mysql-param-type aka https://mysqlconnector.net/troubleshooting/parameter-types/. It's also linked here in the "Migrating" docs: https://mysqlconnector.net/tutorials/migrating-from-connector-net/#mysqlparameter

Is this intentional?

In the sense that everything not supported is prohibited, yes.

Since StringBuilder has a well-known and safe ToString() method, this seems like a reasonable addition.

@appel1
Copy link
Author

appel1 commented Apr 23, 2021

I looked for any mention of types with support removed compared to Connector/NET. Should've read more carefully. Especially the link in the error message that made things clear. Sorry.

@bgrainger
Copy link
Member

I looked for any mention of types with support removed compared to Connector/NET.

The list of types is basically "all of them" because Connector/NET will call .ToString() on anything (which is most often a bug, because ToString usually just returns the type name).

@bgrainger
Copy link
Member

In .NET 5 support for StringBuilder could be implemented using GetChunks, which should be much more efficient than ToString.

@bgrainger
Copy link
Member

Fixed in 1.3.5.

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

No branches or pull requests

2 participants