Size property of Devart.Data.MySql.MySqlParameter class doesn't work as expected.

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
saven
Posts: 1
Joined: Wed 30 May 2018 11:06

Size property of Devart.Data.MySql.MySqlParameter class doesn't work as expected.

Post by saven » Wed 30 May 2018 11:25

I'm inserting new record to table with VarChar(50) column type.
New value is provided with MySqlParameter with following code:

Code: Select all

cmd.Parameters.Add("ProductName", MySqlType.VarChar, 50);
par.Value = "Long-long string that is larger than fifty characters.";


Then, query is executed using cmd.ExecuteNonQuery() method.
As a result MySql server returns "Data too long for column "ProductName" at row 1" error.
BUT, specification says:
"If the size of the value supplied for a DbParameter exceeds the specified Size, the Value of the DbParameter will contain the specified value, truncated to the Size of the DbParameter.".

When I call Add(string parameterName, Devart.Data.MySql.MySqlType dbType, int size) method of Devart.Data.MySql.MySqlParameterCollection, Size property of parameter is set to 50 and I expect provider to truncate the value to 50 characters long.

Version: 8.3.181.0

Pinturiccio
Devart Team
Posts: 2192
Joined: Wed 02 Nov 2011 09:44

Re: Size property of Devart.Data.MySql.MySqlParameter class doesn't work as expected.

Post by Pinturiccio » Mon 04 Jun 2018 12:57

This is the designed behaviour. The Size property is a property of the base DbParameter class, and it is not used in MySqlParameter. Changing behaviour for this property can break backward compatibility for many dotConnect for MySQL users.

You can setup your MySQL server so that the strings were truncated on the server side if the length of the string is more than the column size. For more information, please refer to https://stackoverflow.com/questions/184 ... or-setting

Post Reply