1

So, we're using SubSonic as our DAL/ORM for one of our projects. Everything has been running smoothly (the database already existed, so we used SubSonic on top of it), however, on occasion we'll run into an exception that says something like the integer is exceeding the max length. In this example, our MySql field is an int(4) signed. Which, according to MySql documentation will allow a range of the following:

-2147483647 to 2147483647.

Now, my question, how is MaxLength dictated in SubSonic? Is it the number of digits? Because that means it would only allow -9999 to 9999, correct? That seems like a rather huge discrepancy, and I'm hoping that isn't the case, or else we're going to have a ton of other problems.

Thanks, -Steve

StephenPAdams
  • 2,797
  • 2
  • 30
  • 49
  • Well, if int(4) is -2147483647 to 2147483647, then the 4 refers to the number of bytes, not the number of digits. – Robert Harvey Jan 19 '10 at 22:44
  • See also http://stackoverflow.com/questions/947406/subsonic-sqlite-float-datatype-cant-save-xxx-exceeds-the-maximum-length – Robert Harvey Jan 19 '10 at 22:45
  • More info: Can't save: -field name- exceeds the maximum length of 4 – StephenPAdams Jan 19 '10 at 22:49
  • Robert, the issue is that we're trying to save a value of 10444 into a int(4) database field, which should save fine. However, we're getting the exception above: Can't save: -field name- exceeds the maximum length of 4 – StephenPAdams Jan 19 '10 at 22:50

1 Answers1

0

Using Reflector, and drilling down to ActiveRecord's Save function (which calls ValidateColumnSettings):

 if ((!flag && (column.MaxLength > 0)) && ((column.DataType != DbType.Boolean) && (currentValue.ToString().Length > column.MaxLength)))
        {
            Utility.WriteTrace(string.Format("Max Length Exceeded {0} (can't exceed {1}); current value is set to {2}", column.ColumnName, column.MaxLength, currentValue.ToString().Length));
            this.errorList.Add(string.Format(this.LengthExceptionMessage, str, column.MaxLength));
        }

flag is set to true if the variable is null. So, yes, it's going off of the number of digits (see: ToString().Length). This doesn't seem to make any sense, since MySql doesn't use the length property of the data type to determine the number of digits for integer based values.

This is SubSonic 2.2.

StephenPAdams
  • 2,797
  • 2
  • 30
  • 49
  • In case anyone is wondering, this validate can be disabled by turning off the ValidateWhenSaving property (set it to false). It's enabled by default in the constructor for RecordBase. This solves our issue. It'd be nice if this could be generated for us via the configuration for SubSonic, so we can enable/disable it as we deem fit. – StephenPAdams Jan 21 '10 at 16:17