nhibernate/nhibernate-core — pull request #58 by carstenschuette (2012-01-14 22:42:12+00:00)
Title: NH-2967: Fix for OverflowException on VARCHAR(MAX) columns with mysql

Using the SchemaUpdate tool with MySQL 5 database fails without throwing an exception. It simply runs several seconds, then returns. The following exception can be found in the log files (if they are active):

2011-12-07 09:49:53.467 | 10 | ERROR | SchemaUpdate | could not complete schema update
Exception OverflowException: Der Wert für einen Int32 war zu groß oder zu klein.
bei System.Convert.ToInt32(Int64 value)
bei System.Int64.System.IConvertible.ToInt32(IFormatProvider provider)
bei System.Convert.ToInt32(Object value)
bei NHibernate.Dialect.Schema.MySQLColumnMetadata..ctor(DataRow rs)

MySQL reports a column size of 2^32, which is too large for Int32. Because I did not want to modify the interface, I have created a simple workaround that works for us. Please note that the changes in this pull request ae different from the patch I added to the JIRA issue some weeks ago. I have done the same changes to all metadata classes because the same thing could happen on all other database types, too.

The current changes do not change the interface but add two new protected methods "SetColumnSize" and "SetNumericalPrecision" to AbstractColumnMetaData which handle the values from the metadata result set. The ColumnSize and NumericPrecision properties are never used in nhibernate-core, but might be used by others.

I think the risk of side effects is low, because a field size larger than 2^31 which should not be handled as "MAX" is somewhat unusual. It is lower than the risk that others use the ColumnSize field and expect it as "int" value and get in trouble when the type changes to "long". Also, field sizes larger than 2^31 never worked here in the past.