[Mono-bugs] [Bug 650837] New: MaxLength should be ignored if EnforceConstraints = false
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Tue Nov 2 17:38:08 EDT 2010
https://bugzilla.novell.com/show_bug.cgi?id=650837
https://bugzilla.novell.com/show_bug.cgi?id=650837#c0
Summary: MaxLength should be ignored if EnforceConstraints =
false
Classification: Mono
Product: Mono: Class Libraries
Version: 2.6.x
Platform: x86
OS/Version: Windows 7
Status: NEW
Severity: Normal
Priority: P5 - None
Component: Sys.Data
AssignedTo: mono-bugs at lists.ximian.com
ReportedBy: cvolzke at live.com.au
QAContact: mono-bugs at lists.ximian.com
Found By: ---
Blocker: ---
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US)
AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.1.249.1036 Safari/532.5
MaxLength should be ignored if EnforceConstraints = false
Reproducible: Always
Steps to Reproduce:
Test case:
DataSet data = new DataSet();
DataTable table = new DataTable();
data.Tables.Add(table);
DataColumn column = table.Columns.Add("column");
column.MaxLength = 5;
table.Rows.Add("value");
data.EnforceConstraints = false;
table.Rows[0][0] = "exceeded"; // expect no exception
try
{
data.EnforceConstraints = true;
}
catch (ConstraintException)
{
}
table.Rows[0][0] = "value";
data.EnforceConstraints = true; // expect no exception
try
{
table.Rows[0][0] = "exceeded";
}
catch (ConstraintException)
{
}
Actual Results:
Exceptions thrown when table.Rows[0][0] = "exceeded"; is first set above.
Expected Results:
No exception thrown when table.Rows[0][0] = "exceeded"; is first set above.
An exception is thrown when EnforceConstraints = true after exceeding MaxLength
Proposed fix:
StringDataContainer
-------------------
sealed class StringDataContainer : ObjectDataContainer {
private void SetValue (int index, string value)
{
if (value != null && Column.MaxLength >= 0 && Column.MaxLength <
value.Length
&& Column.Table.DataSet.EnforceConstraints // line added
)
throw new ArgumentException ("Cannot set column '" + Column.ColumnName
+ "' to '" + value + "'. The value violates the MaxLength limit of this
column.");
base.SetValue (index, value);
}
DataSet.InternalEnforceConstraints
----------------------------------
Add to the end of InternalEnforceConstraints()
foreach (DataTable table in Tables)
{
foreach (DataRow row in table.Rows)
{
if (row.RowState == DataRowState.Added ||
row.RowState == DataRowState.Modified)
continue;
foreach (DataColumn column in table.Columns)
{
if (column.MaxLength != -1 &&
column.DataType == typeof(string))
{
string str = row[column] as string;
if (str != null && str.Length > column.MaxLength)
{
throw new ConstraintException("Column '" +
column.ColumnName + "' exceeds the MaxLength limit.");
}
}
}
}
}
--
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.
More information about the mono-bugs
mailing list