2004-11-10 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Wed, 10 Nov 2004 09:11:37 +0000 (09:11 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Wed, 10 Nov 2004 09:11:37 +0000 (09:11 -0000)
* CustomDataClassGenerator.cs : generated foreign key constraint
  construction code was creating empty child columns and thus it
  was invalid. This fixes bug #69276 (patch by Martin Voelkle).

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

mcs/class/System.Data/System.Data/ChangeLog
mcs/class/System.Data/System.Data/CustomDataClassGenerator.cs

index 4d618836b48e699ffe908668df43a4ef4c54f6c4..2e55f49333c476be84d51507e5f30e033ceb3a20 100644 (file)
@@ -1,3 +1,9 @@
+2004-11-10  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * CustomDataClassGenerator.cs : generated foreign key constraint
+         construction code was creating empty child columns and thus it
+         was invalid. This fixes bug #69276 (patch by Martin Voelkle).
+
 2004-11-02  Atsushi Enomoto  <atsushi@ximian.com>
 
        * CustomDataClassGenerator.cs : custom DataTable ctor should call
index efde5344b58c892f742b754832e6462e17278c74..9d2ba26efb77a149e60303289bb60f803aa3fb89 100755 (executable)
@@ -693,6 +693,7 @@ namespace System.Data
 
                        bool fkcExists = false;
                        bool ucExists = false;
+                       // First the UniqueConstraints
                        foreach (DataTable dt in ds.Tables) {
                                string tname = "__table" + opts.TableMemberName (dt.TableName, gen);
                                foreach (Constraint c in dt.Constraints) {
@@ -703,19 +704,25 @@ namespace System.Data
                                                        ucExists = true;
                                                }
                                                CreateUniqueKeyStatements (m, uc, tname);
-                                               continue;
                                        }
+                               }
+                       }
+                       // Then the ForeignKeyConstraints
+                       foreach (DataTable dt in ds.Tables) {
+                               string tname = "__table" + opts.TableMemberName (dt.TableName, gen);
+                               foreach (Constraint c in dt.Constraints) {
                                        ForeignKeyConstraint fkc = c as ForeignKeyConstraint;
                                        if (fkc != null) {
                                                if (!fkcExists) {
                                                        m.Statements.Add (VarDecl (typeof (ForeignKeyConstraint), "fkc", null));
                                                        fkcExists = true;
                                                }
-                                               CreateForeignKeyStatements (m, fkc, tname);
+                                               string rtname = "__table" + opts.TableMemberName (fkc.RelatedTable.TableName, gen);
+                                               CreateForeignKeyStatements (m, fkc, tname, rtname);
                                        }
-                                       // What if other cases? dunno. Just ignore ;-)
                                }
                        }
+                       // What if other cases? dunno. Just ignore ;-)
                        foreach (DataRelation rel in ds.Relations) {
                                string relName = opts.RelationName (rel.RelationName, gen);
                                ArrayList pcols = new ArrayList ();
@@ -756,15 +763,15 @@ namespace System.Data
                        m.Statements.Add (MethodInvoke (PropRef (FieldRef (tableField), "Constraints"), "Add", Local ("uc")));
                }
 
-               private void CreateForeignKeyStatements (CodeMemberMethod m,ForeignKeyConstraint fkc, string tableField)
+               private void CreateForeignKeyStatements (CodeMemberMethod m,ForeignKeyConstraint fkc, string tableField, string rtableField)
                {
                        ArrayList pcols = new ArrayList ();
-                       foreach (DataColumn col in fkc.Columns)
-                               pcols.Add (IndexerRef (PropRef (FieldRef (tableField), "Columns"), Const (col.ColumnName)));
+                       foreach (DataColumn col in fkc.RelatedColumns)
+                               pcols.Add (IndexerRef (PropRef (FieldRef (rtableField), "Columns"), Const (col.ColumnName)));
 
                        ArrayList ccols = new ArrayList ();
-                       foreach (DataColumn col in fkc.RelatedColumns)
-                               pcols.Add (IndexerRef (PropRef (FieldRef (tableField), "Columns"), Const (col.ColumnName)));
+                       foreach (DataColumn col in fkc.Columns)
+                               ccols.Add (IndexerRef (PropRef (FieldRef (tableField), "Columns"), Const (col.ColumnName)));
 
                        m.Statements.Add (Let (Local ("fkc"), New (
                                typeof (ForeignKeyConstraint),