2008-06-19 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Thu, 19 Jun 2008 16:35:24 +0000 (16:35 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Thu, 19 Jun 2008 16:35:24 +0000 (16:35 -0000)
* DataRelation.cs : keep createConstraints flag for cloning in
  DataSet.Merge(). Use different flag for initialization instead.
* MergeManager.cs : When cloning DataRelation, createConstraints
  flag should depend on the source.
* XmlSchemaDataImporter.cs : create constraints when creating
  DataRelation.

* TestMerge1.xml : new test file.
* DataSetTest2.cs : added test for Merge() to verify that it copies
  constraints in DataRelation.

svn path=/trunk/mcs/; revision=106227

mcs/class/System.Data/System.Data/ChangeLog
mcs/class/System.Data/System.Data/DataRelation.cs
mcs/class/System.Data/System.Data/MergeManager.cs
mcs/class/System.Data/System.Data/XmlSchemaDataImporter.cs
mcs/class/System.Data/Test/System.Data/ChangeLog
mcs/class/System.Data/Test/System.Data/DataSetTest2.cs
mcs/class/System.Data/Test/System.Data/TestMerge1.xml [new file with mode: 0644]

index 345da2a0cb09b9e1641f3133ce777d6b17c0c297..e1062b7e10bfa8ba784c69ebe8e4a89e7edb0167 100644 (file)
@@ -1,3 +1,12 @@
+2008-06-19  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * DataRelation.cs : keep createConstraints flag for cloning in
+         DataSet.Merge(). Use different flag for initialization instead.
+       * MergeManager.cs : When cloning DataRelation, createConstraints
+         flag should depend on the source.
+       * XmlSchemaDataImporter.cs : create constraints when creating
+         DataRelation.
+
 2008-06-18  Atsushi Enomoto  <atsushi@ximian.com>
 
        * DataSet.cs : when InferSchema mode, ReadXml() should do "merging
index 498a266a149c7ae7157402ccff5b1906e0ba27e0..d268e00e3eb32060b2c3eae4c7d5f763e8ab3ecb 100644 (file)
@@ -59,7 +59,8 @@ namespace System.Data
                private DataColumn[] parentColumns;
                private DataColumn[] childColumns;
                private bool nested;
-               internal bool createConstraints;
+               internal bool createConstraints = true;
+               private bool initFinished;
                private PropertyCollection extendedProperties;
                private PropertyChangedEventHandler onPropertyChangingDelegate;
 
@@ -183,7 +184,7 @@ namespace System.Data
 
                        this.RelationName = _relationName;
                        this.Nested = _nested;
-                       this.createConstraints = false;
+                       this.initFinished = true;
                        this.extendedProperties = new PropertyCollection ();
                        InitInProgress = false;
 #if NET_2_0
@@ -345,7 +346,7 @@ namespace System.Data
                 
         internal void UpdateConstraints ()
         {
-            if ( ! createConstraints)
+            if (initFinished || ! createConstraints)
                 return;
             
             ForeignKeyConstraint    foreignKeyConstraint    = null;
index af4fd7e40735c9207f415f1f4e83c488e6a185ae..cf63a05967f1f89f7d4e141068132b73e0302604 100644 (file)
@@ -223,7 +223,7 @@ namespace System.Data
                                        DataColumn[] childColumns = ResolveColumns (targetSet.Tables [relation.ChildTable.TableName],
                                                        relation.ChildColumns);
                                        targetRelation = targetSet.Relations.Add (relation.RelationName, parentColumns,
-                                                       childColumns, false);
+                                                       childColumns, relation.createConstraints);
                                        targetRelation.Nested = relation.Nested;
                                } else if (!CompareColumnArrays (relation.ParentColumns, targetRelation.ParentColumns) ||
                                                !CompareColumnArrays (relation.ChildColumns, targetRelation.ChildColumns)) {
index 7c16d78993f888c2b2b0fdeb683aa723e0ba29ce..749b3799c75fde1e9f4b8bf0c01a6a215e80a419 100644 (file)
@@ -1162,7 +1162,7 @@ namespace System.Data
 
                        if (!c.IsConstraintOnly) {
                                // generate the relation.
-                               DataRelation rel = new DataRelation (c.ConstraintName, uniq.Columns, cols, false);
+                               DataRelation rel = new DataRelation (c.ConstraintName, uniq.Columns, cols, true);
                                rel.Nested = c.IsNested;
                                rel.SetParentKeyConstraint (uniq);
                                rel.SetChildKeyConstraint (fkc);
index 60bd10fa95b1dfc801e5f3ec15fccc6b55b906b6..721bcefc1575eeab85fa91a36c23d4a75c7cd715 100644 (file)
@@ -1,3 +1,9 @@
+2008-06-19  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * TestMerge1.xml : new test file.
+       * DataSetTest2.cs : added test for Merge() to verify that it copies
+         constraints in DataRelation.
+
 2008-06-18  Atsushi Enomoto  <atsushi@ximian.com>
 
        * DataTableTest.cs : do not just copy [Ignore]d tests from DataSet
index ae848d97029ceff3e8c3473544cdaa3667aa857f..56cfbefaf06a91b505001a2d67f8c8ff9cd97f1d 100644 (file)
@@ -1474,7 +1474,7 @@ namespace MonoTests_System.Data
                        ds.Merge (ds1);
                        Assert.AreEqual (1, ds.Relations.Count , "#1");
                        Assert.AreEqual (0, ds.Tables [0].Constraints.Count , "#2");
-                       Assert.AreEqual (0, ds.Tables [1].Constraints.Count , "#2");
+                       Assert.AreEqual (0, ds.Tables [1].Constraints.Count , "#3");
                }
 
                [Test]
@@ -1549,6 +1549,18 @@ namespace MonoTests_System.Data
                        Assert.AreEqual (0, ds2.Tables [1].Constraints.Count, "#6");
                }
 
+               [Test]
+               public void Merge_ConstraintsFromReadXmlSchema ()
+               {
+                       DataSet ds = new DataSet ();
+                       ds.ReadXml ("Test/System.Data/TestMerge1.xml");
+                       DataSet ds2 = new DataSet ();
+                       ds2.Merge (ds, true, MissingSchemaAction.AddWithKey);
+                       DataRelation c = ds2.Tables [0].ChildRelations [0];
+                       Assert.IsNotNull (c.ParentKeyConstraint, "#1");
+                       Assert.IsNotNull (c.ChildKeyConstraint, "#2");
+               }
+
                [Test]
                [ExpectedException (typeof (DataException))]
                public void Merge_MissingEventHandler ()
diff --git a/mcs/class/System.Data/Test/System.Data/TestMerge1.xml b/mcs/class/System.Data/Test/System.Data/TestMerge1.xml
new file mode 100644 (file)
index 0000000..de17ac4
--- /dev/null
@@ -0,0 +1,64 @@
+<MyDataSet>
+  <xs:schema id="MyDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xs:element name="MyDataSet" msdata:IsDataSet="true" msdata:MainDataTable="Main" msdata:UseCurrentLocale="true">
+      <xs:complexType>
+        <xs:choice minOccurs="0" maxOccurs="unbounded">
+          <xs:element name="Main">
+            <xs:complexType>
+              <xs:sequence>
+                <xs:element name="ID" type="xs:int" minOccurs="0" />
+                <xs:element name="Data" type="xs:string" minOccurs="0" />
+              </xs:sequence>
+            </xs:complexType>
+          </xs:element>
+          <xs:element name="Child">
+            <xs:complexType>
+              <xs:sequence>
+                <xs:element name="ID" type="xs:int" minOccurs="0" />
+                <xs:element name="PID" type="xs:int" minOccurs="0" />
+                <xs:element name="ChildData" type="xs:string" minOccurs="0" />
+              </xs:sequence>
+            </xs:complexType>
+          </xs:element>
+        </xs:choice>
+      </xs:complexType>
+      <xs:unique name="Constraint1">
+        <xs:selector xpath=".//Main" />
+        <xs:field xpath="ID" />
+      </xs:unique>
+      <xs:keyref name="MainToChild" refer="Constraint1">
+        <xs:selector xpath=".//Child" />
+        <xs:field xpath="PID" />
+      </xs:keyref>
+    </xs:element>
+  </xs:schema>
+  <Main>
+    <ID>1</ID>
+    <Data>One</Data>
+  </Main>
+  <Main>
+    <ID>2</ID>
+    <Data>Two</Data>
+  </Main>
+  <Main>
+    <ID>3</ID>
+    <Data>Three</Data>
+  </Main>
+  <Child>
+    <ID>1</ID>
+    <PID>1</PID>
+    <ChildData>Parent1Child1</ChildData>
+  </Child>
+  <Child>
+    <ID>2</ID>
+    <PID>1</PID>
+    <ChildData>Parent1Child2</ChildData>
+  </Child>
+  <Child>
+    <ID>3</ID>
+    <PID>2</PID>
+    <ChildData>Parent2Child3</ChildData>
+  </Child>
+</MyDataSet>
+