Page 1 of 1

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

Posted: Wed 30 May 2018 11:25
by saven
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

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

Posted: Mon 04 Jun 2018 12:57
by Pinturiccio
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