[system.data] BUGFIX: fixes issue with expression columns and IsNull:
authorMatthew Leibowitz <mattleibow@live.com>
Fri, 27 Jun 2014 11:43:12 +0000 (13:43 +0200)
committerMatthew Leibowitz <mattleibow@live.com>
Fri, 27 Jun 2014 11:43:12 +0000 (13:43 +0200)
 - bugzilla.xamarin.com issue 20925
 - if an expression column was added ayer there were rows, and then IsNull is called, the result is incorrect (it will always be true)

mcs/class/System.Data/System.Data/DataRow.cs
mcs/class/System.Data/Test/System.Data/DataRowTest2.cs

index 6b6299f41a82c490d4a0e79d244fbc197633cfd9..2edb8fb50567ad0b36a78be5e53dba211102c4c6 100644 (file)
@@ -1257,6 +1257,14 @@ namespace System.Data {
                /// </summary>
                public bool IsNull (DataColumn column, DataRowVersion version)
                {
+                       // use the expresion if there is one
+                       if (column.Expression != String.Empty) {
+                               // FIXME: how does this handle 'version'?
+                               // TODO: Can we avoid the Eval each time by using the cached value?
+                               object o = column.CompiledExpression.Eval (this);
+                               return o == null && o == DBNull.Value;
+                       }
+
                        return column.DataContainer.IsNull (IndexFromVersion (version));
                }
 
index 14333e2201ad4599e3d68507d6cc19c4a6a4b380..7e31ae821c1264fe87e3001bffec4c24754a1c05 100644 (file)
@@ -2125,6 +2125,28 @@ namespace MonoTests.System.Data
 #endregion
                }
 
+               [Test]
+               public void IsNull_BeforeGetValue ()
+               {
+                       DataTable table = new DataTable ();
+
+                       // add the row, with the value in the column
+                       DataColumn staticColumn = table.Columns.Add ("static", typeof(string), null); // static
+                       DataRow row = table.Rows.Add ("the value");
+                       Assert.IsFalse (row.IsNull ("static"), "static null check failed");
+                       Assert.AreEqual ("the value", row ["static"], "static value check failed");
+
+                       // add the first derived column
+                       DataColumn firstColumn = table.Columns.Add ("first", typeof(string), "static"); // first -> static
+                       Assert.IsFalse (row.IsNull ("first"), "first level null check failed");
+                       Assert.AreEqual ("the value", row ["first"], "first level value check failed");
+
+                       // add the second level of related
+                       DataColumn secondColumn = table.Columns.Add ("second", typeof(string), "first"); // second -> first -> static
+                       Assert.IsFalse (row.IsNull ("second"), "second level null check failed");
+                       Assert.AreEqual ("the value", row ["second"], "second level value check failed");
+               }
+
                [Test] public void Item()
                {
                        // init table with columns