Repository navigation
Closed
Description
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
Metadata
Metadata
Assignees
Labels
No labels
Activity
bgrainger commentedon Apr 23, 2021
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
In the sense that everything not supported is prohibited, yes.
Since
StringBuilderhas a well-known and safeToString()method, this seems like a reasonable addition.appel1 commentedon 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 commentedon Apr 23, 2021
The list of types is basically "all of them" because Connector/NET will call
.ToString()on anything (which is most often a bug, becauseToStringusually just returns the type name).bgrainger commentedon Apr 23, 2021
In .NET 5 support for
StringBuildercould be implemented usingGetChunks, which should be much more efficient thanToString.Support StringBuilder in MySqlParameter. Fixes #975
bgrainger commentedon Apr 23, 2021
Fixed in 1.3.5.