DataRow.cs : SetParentRow on Detached row with no Default version throws an exception...
authorBoris Kirzner <borisk@mono-cvs.ximian.com>
Tue, 31 May 2005 12:01:30 +0000 (12:01 -0000)
committerBoris Kirzner <borisk@mono-cvs.ximian.com>
Tue, 31 May 2005 12:01:30 +0000 (12:01 -0000)
svn path=/trunk/mcs/; revision=45260

mcs/class/System.Data/ChangeLog
mcs/class/System.Data/System.Data/ChangeLog
mcs/class/System.Data/System.Data/DataRow.cs
mcs/class/System.Data/System.Data_test.dll.sources
mcs/class/System.Data/Test/System.Data.Tests.Mainsoft/System.Data/RowNotInTableException/RowNotInTableException_Generate.cs [new file with mode: 0644]

index 2948edf04c09815a3da84ff8de2fa62b8855a3f0..4661417706a920523646d86202048a953b99fb53 100644 (file)
@@ -1,3 +1,6 @@
+2005-05-31 Boris Kirzner <borisk@mainsoft.com>
+               * System.Data_test.dll.sources : added System.Data.Tests.Mainsoft/System.Data/RowNotInTableException/RowNotInTableException_Generate.cs
+               
 2005-05-30 BorisKirzner <borisk@mainsoft.com>
                * System.Data.SqlClient.jvm
                * System.Data.Configuration.jvm
index 9560081f0e1d9625c5dc1500d102b19a887fc750..6ce043d5dd081d3809cd05aed7942155276c69c5 100644 (file)
@@ -1,3 +1,6 @@
+2005-05-31 Boris Kirzner <borisk@mainsoft.com>
+       * DataRow.cs : SetParentRow on Detached row with no Default version throws an exception.
+       
 2005-05-29 Konstantin Triger <kostat@mainsoft.com>
 
        * This patch fixes #74813
index 9a22f2c25a90474d63d5f42e145521586ed18797..9c014aa4c453921e7924e470d3f7527b7f7484b8 100644 (file)
@@ -1393,6 +1393,11 @@ namespace System.Data {
 
                        if (parentRow != null && _table.DataSet != parentRow.Table.DataSet)
                                throw new ArgumentException();
+
+                       if (RowState == DataRowState.Detached && !HasVersion(DataRowVersion.Default)) {
+                               // the row should have default data to access, i.e. we can do this for the newly created row, but not for the row once deleted from the table
+                               throw new RowNotInTableException("This row has been removed from a table and does not have any data.  BeginEdit() will allow creation of new data in this row.");
+                       }
                        
                        BeginEdit();
 
index 547dcabf4cd40e005de1f5cf497efa9c9ea6b0b6..6236fba38592c9ba9c86f896d457477eafdfb5bc 100644 (file)
@@ -334,6 +334,7 @@ System.Data.Tests.Mainsoft/System.Data/InRowChangingEventException/InRowChanging
 System.Data.Tests.Mainsoft/System.Data/InvalidConstraintException/InvalidConstraintException_Generate.cs
 System.Data.Tests.Mainsoft/System.Data/NoNullAllowedException/NoNullAllowedException_Generate.cs
 System.Data.Tests.Mainsoft/System.Data/ReadOnlyException/ReadOnlyException_Generate.cs
+System.Data.Tests.Mainsoft/System.Data/RowNotInTableException/RowNotInTableException_Generate.cs
 System.Data.Tests.Mainsoft/System.Data/SyntaxErrorException/SyntaxErrorException_Generate.cs
 System.Data.Tests.Mainsoft/System.Data/UniqueConstraint/UniqueConstraint_Columns.cs
 System.Data.Tests.Mainsoft/System.Data/UniqueConstraint/UniqueConstraint_constraintName.cs
diff --git a/mcs/class/System.Data/Test/System.Data.Tests.Mainsoft/System.Data/RowNotInTableException/RowNotInTableException_Generate.cs b/mcs/class/System.Data/Test/System.Data.Tests.Mainsoft/System.Data/RowNotInTableException/RowNotInTableException_Generate.cs
new file mode 100644 (file)
index 0000000..289c9d8
--- /dev/null
@@ -0,0 +1,213 @@
+// Authors:
+//   Rafael Mizrahi   <rafim@mainsoft.com>
+//   Erez Lotan       <erezl@mainsoft.com>
+//   Oren Gurfinkel   <oreng@mainsoft.com>
+//   Ofer Borstein
+// 
+// Copyright (c) 2004 Mainsoft Co.
+// 
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//\r
+\r
+using NUnit.Framework;
+
+
+using System;
+using System.Data;
+
+using GHTUtils;
+using GHTUtils.Base;\r
+\r
+namespace tests.system_data_dll.System_Data
+{\r
+[TestFixture] public class RowNotInTableException_Generate : GHTBase\r
+{\r
+       [Test] public void Main()\r
+       {\r
+               RowNotInTableException_Generate tc = new RowNotInTableException_Generate();\r
+               Exception exp = null;\r
+               try\r
+               {\r
+                       tc.BeginTest("RowNotInTableException");\r
+                       tc.run();\r
+               }\r
+               catch(Exception ex)\r
+               {\r
+                       exp = ex;\r
+               }\r
+               finally\r
+               {\r
+                       tc.EndTest(exp);\r
+               }\r
+       }\r
+\r
+       //Activate This Construntor to log All To Standard output\r
+       //public TestClass():base(true){}\r
+\r
+       //Activate this constructor to log Failures to a log file\r
+       //public TestClass(System.IO.TextWriter tw):base(tw, false){}\r
+\r
+\r
+       //Activate this constructor to log All to a log file\r
+       //public TestClass(System.IO.TextWriter tw):base(tw, true){}\r
+\r
+       //BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES\r
+\r
+       public void run()\r
+       {\r
+               Exception exp = null;\r
+               Exception tmpEx = new Exception() ;\r
+\r
+               DataSet ds = new DataSet();\r
+               ds.Tables.Add(GHTUtils.DataProvider.CreateParentDataTable());\r
+               ds.Tables.Add(GHTUtils.DataProvider.CreateChildDataTable());\r
+               ds.Relations.Add(new DataRelation("myRelation",ds.Tables[0].Columns[0],ds.Tables[1].Columns[0]));\r
+\r
+               DataRow drParent = ds.Tables[0].Rows[0];\r
+               DataRow drChild = ds.Tables[1].Rows[0];\r
+               drParent.Delete();\r
+               drChild.Delete();\r
+               ds.AcceptChanges();\r
+        \r
+               try\r
+               {\r
+                       BeginCase("RowNotInTableException - AcceptChanges");\r
+                       try\r
+                       {\r
+                               drParent.AcceptChanges();\r
+                       }\r
+                       catch (RowNotInTableException  ex)\r
+                       {\r
+                               tmpEx = ex;\r
+                       }\r
+                       base.Compare(tmpEx.GetType(),typeof(RowNotInTableException));\r
+                       tmpEx = new  Exception();\r
+               }\r
+               catch(Exception ex)     {exp = ex;}\r
+               finally {EndCase(exp); exp = null;}\r
+\r
+               try\r
+               {\r
+                       BeginCase("RowNotInTableException - GetChildRows");\r
+                       try\r
+                       {\r
+                               drParent.GetChildRows("myRelation");\r
+                       }\r
+                       catch (RowNotInTableException  ex)\r
+                       {\r
+                               tmpEx = ex;\r
+                       }\r
+                       base.Compare(tmpEx.GetType(),typeof(RowNotInTableException));\r
+                       tmpEx = new  Exception();\r
+               }\r
+               catch(Exception ex)     {exp = ex;}\r
+               finally {EndCase(exp); exp = null;}\r
+\r
+               try\r
+               {\r
+                       BeginCase("RowNotInTableException - ItemArray");\r
+                       object[] o = null;\r
+                       try\r
+                       {\r
+                               o = drParent.ItemArray ;\r
+                       }\r
+                       catch (RowNotInTableException  ex)\r
+                       {\r
+                               tmpEx = ex;\r
+                       }\r
+                       base.Compare(tmpEx.GetType(),typeof(RowNotInTableException));\r
+                       tmpEx = new  Exception();\r
+               }\r
+               catch(Exception ex)     {exp = ex;}\r
+               finally {EndCase(exp); exp = null;}\r
+\r
+               // **********   don't throw exception (should be according to MSDN)     ***********************\r
+               //              try\r
+               //              {\r
+               //                      BeginCase("RowNotInTableException - GetParentRow");\r
+               //                      DataRow dr = null;\r
+               //                      try\r
+               //                      {\r
+               //                              dr = drChild.GetParentRow("myRelation"); \r
+               //                      }\r
+               //                      catch (RowNotInTableException  ex)\r
+               //                      {\r
+               //                              tmpEx = ex;\r
+               //                      }\r
+               //                      base.Compare(tmpEx.GetType(),typeof(RowNotInTableException));\r
+               //                      tmpEx = new  Exception();\r
+               //              }\r
+               //              catch(Exception ex)     {exp = ex;}\r
+               //              finally {EndCase(exp); exp = null;}\r
+               \r
+               try\r
+               {\r
+                       BeginCase("RowNotInTableException - GetParentRows");\r
+                       DataRow[] dr = null;\r
+                       try\r
+                       {\r
+                               dr = drChild.GetParentRows("myRelation"); \r
+                       }\r
+                       catch (RowNotInTableException  ex)\r
+                       {\r
+                               tmpEx = ex;\r
+                       }\r
+                       base.Compare(tmpEx.GetType(),typeof(RowNotInTableException));\r
+                       tmpEx = new  Exception();\r
+               }\r
+               catch(Exception ex)     {exp = ex;}\r
+               finally {EndCase(exp); exp = null;}\r
+\r
+               try\r
+               {\r
+                       BeginCase("RowNotInTableException - RejectChanges");\r
+                       try\r
+                       {\r
+                               drParent.RejectChanges();\r
+                       }\r
+                       catch (RowNotInTableException  ex)\r
+                       {\r
+                               tmpEx = ex;\r
+                       }\r
+                       base.Compare(tmpEx.GetType(),typeof(RowNotInTableException));\r
+                       tmpEx = new  Exception();\r
+               }\r
+               catch(Exception ex)     {exp = ex;}\r
+               finally {EndCase(exp); exp = null;}\r
+\r
+               try\r
+               {\r
+                       BeginCase("RowNotInTableException - SetParentRow");\r
+                       try\r
+                       {\r
+                               drChild.SetParentRow(ds.Tables[0].Rows[1]);\r
+                       }\r
+                       catch (RowNotInTableException  ex)\r
+                       {\r
+                               tmpEx = ex;\r
+                       }\r
+                       base.Compare(tmpEx.GetType(),typeof(RowNotInTableException));\r
+                       tmpEx = new  Exception();\r
+               }\r
+               catch(Exception ex)     {exp = ex;}\r
+               finally {EndCase(exp); exp = null;}\r
+       }\r
+}\r
+}
\ No newline at end of file