From 32d87915940b7c6af91ef5b256e252906d041b9c Mon Sep 17 00:00:00 2001 From: Nagappan Alagappan Date: Tue, 28 Nov 2006 06:32:38 +0000 Subject: [PATCH] 2006-11-28 Nagappan A * DataRelation.cs (DataRelation): Added 2.0 profile constructor to take parentTableNameSpace and childTableNameSpace as argument. (FinishInit): Update parentTableNameSpace and childTableNameSpace, when the string is not empty in 2.0 profile. * DataRowCollection.cs: Implemented Count public property. Added !NET_2_0 for List protected property, as it has been removed in 2.0 prifle. (IndexOf): Implemented new public method. (CopyTo): Implemented new public override method. (GetEnumerator): Implemented new public override method. * DataTable.cs (Load): Throw ArgumentNullException, when reader argument is null. (WriteXmlSchema): Throw InvalidOperationException, when table name is empty. When DataSet Namespace is set, append that with '_x003A_' and table name. * DataSet.cs (Load): Throw ArgumentNullException, when reader argument is null. * XmlSchemaWriter.cs (WriteSchema): Modified UseCurrentCulture to UseCurrentLocale. (WriteDataSetElement): Added minOccurs attribute. (WriteConstraints): Check for tables length, if > 1 then add the relations to XmlSchema. svn path=/trunk/mcs/; revision=68563 --- mcs/class/System.Data/System.Data/ChangeLog | 29 +++++++ .../System.Data/System.Data/DataColumn.cs | 9 -- .../System.Data/System.Data/DataRelation.cs | 37 ++++++-- .../System.Data/DataRelationCollection.cs | 16 ++-- .../System.Data/DataRowCollection.cs | 40 ++++++++- mcs/class/System.Data/System.Data/DataSet.cs | 15 ++-- .../System.Data/System.Data/DataTable.cs | 85 ++++++++++++++++--- .../System.Data/XmlSchemaWriter.cs | 10 ++- 8 files changed, 194 insertions(+), 47 deletions(-) diff --git a/mcs/class/System.Data/System.Data/ChangeLog b/mcs/class/System.Data/System.Data/ChangeLog index d4da4cf6ab2..afbbb653f7b 100644 --- a/mcs/class/System.Data/System.Data/ChangeLog +++ b/mcs/class/System.Data/System.Data/ChangeLog @@ -1,3 +1,32 @@ +2006-11-28 Nagappan A + + * DataRelation.cs (DataRelation): Added 2.0 profile constructor to + take parentTableNameSpace and childTableNameSpace as argument. + (FinishInit): Update parentTableNameSpace and childTableNameSpace, + when the string is not empty in 2.0 profile. + + * DataRowCollection.cs: Implemented Count public property. + Added !NET_2_0 for List protected property, as it has been removed + in 2.0 prifle. + (IndexOf): Implemented new public method. + (CopyTo): Implemented new public override method. + (GetEnumerator): Implemented new public override method. + + * DataTable.cs (Load): Throw ArgumentNullException, when reader + argument is null. + (WriteXmlSchema): Throw InvalidOperationException, when table name + is empty. When DataSet Namespace is set, append that with '_x003A_' + and table name. + + * DataSet.cs (Load): Throw ArgumentNullException, when reader + argument is null. + + * XmlSchemaWriter.cs (WriteSchema): Modified UseCurrentCulture to + UseCurrentLocale. + (WriteDataSetElement): Added minOccurs attribute. + (WriteConstraints): Check for tables length, if > 1 then add the + relations to XmlSchema. + 2006-11-21 Nagappan A * DataView.cs: Added public event Initialized. diff --git a/mcs/class/System.Data/System.Data/DataColumn.cs b/mcs/class/System.Data/System.Data/DataColumn.cs index 1ffd5a578bc..424eb2c2ff4 100644 --- a/mcs/class/System.Data/System.Data/DataColumn.cs +++ b/mcs/class/System.Data/System.Data/DataColumn.cs @@ -786,15 +786,6 @@ namespace System.Data { #region Methods -/* ?? - [MonoTODO] - protected internal void CheckNotAllowNull() { - } - - [MonoTODO] - protected void CheckUnique() { - } -*/ [MonoTODO] internal DataColumn Clone() { DataColumn copy = new DataColumn (); diff --git a/mcs/class/System.Data/System.Data/DataRelation.cs b/mcs/class/System.Data/System.Data/DataRelation.cs index 28ce7a88381..7a2fea79fe2 100644 --- a/mcs/class/System.Data/System.Data/DataRelation.cs +++ b/mcs/class/System.Data/System.Data/DataRelation.cs @@ -71,6 +71,10 @@ namespace System.Data string[] _childColumnNames; bool _nested; bool initInProgress = false; +#if NET_2_0 + string _parentTableNameSpace = String.Empty; + string _childTableNameSpace = String.Empty; +#endif #region Constructors @@ -118,7 +122,6 @@ namespace System.Data "matching column types"); } - [MonoTODO] [Browsable (false)] public DataRelation (string relationName, string parentTableName, string childTableName, string[] parentColumnNames, string[] childColumnNames, bool nested) { @@ -130,6 +133,25 @@ namespace System.Data _nested = nested; InitInProgress = true; } + +#if NET_2_0 + [Browsable (false)] + public DataRelation (string relationName, string parentTableName, + string parentTableNameSpace, string childTableName, + string childTableNameSpace, string[] parentColumnNames, + string[] childColumnNames, bool nested) + { + _relationName = relationName; + _parentTableName = parentTableName; + _parentTableNameSpace = parentTableNameSpace; + _childTableName = childTableName; + _childTableNameSpace = childTableNameSpace; + _parentColumnNames = parentColumnNames; + _childColumnNames = childColumnNames; + _nested = nested; + InitInProgress = true; + } +#endif internal bool InitInProgress { get { return initInProgress; } @@ -165,14 +187,15 @@ namespace System.Data this.createConstraints = false; this.extendedProperties = new PropertyCollection (); InitInProgress = false; - } #if NET_2_0 - [MonoTODO] - public DataRelation (string relationName, string parentTableName, string parentTableNamespace, string childTableName, string childTableNamespace, string[] parentColumnNames, string[] childColumnNames, bool nested) - { - throw new NotImplementedException (); - } + if (_parentTableNameSpace != String.Empty) { + parent.Namespace = _parentTableNameSpace; + } + if (_childTableNameSpace != String.Empty) { + child.Namespace = _childTableNameSpace; + } #endif + } #endregion // Constructors diff --git a/mcs/class/System.Data/System.Data/DataRelationCollection.cs b/mcs/class/System.Data/System.Data/DataRelationCollection.cs index cb40aaf87d1..52208e25404 100644 --- a/mcs/class/System.Data/System.Data/DataRelationCollection.cs +++ b/mcs/class/System.Data/System.Data/DataRelationCollection.cs @@ -246,7 +246,6 @@ namespace System.Data { /// Adds a DataRelation to the DataRelationCollection. /// /// The DataRelation to add to the collection. - [MonoTODO] public void Add(DataRelation relation) { // To prevent endless recursion @@ -259,6 +258,9 @@ namespace System.Data { try { + CollectionChangeEventArgs e = new CollectionChangeEventArgs (CollectionChangeAction.Add, this); + OnCollectionChanging (e); + this.AddCore (relation); if(relation.RelationName == string.Empty) relation.RelationName = GenerateRelationName(); @@ -266,8 +268,8 @@ namespace System.Data { relation.ParentTable.ResetPropertyDescriptorsCache(); relation.ChildTable.ResetPropertyDescriptorsCache(); - CollectionChangeEventArgs e = new CollectionChangeEventArgs(CollectionChangeAction.Add, this); - OnCollectionChanged(e); + e = new CollectionChangeEventArgs (CollectionChangeAction.Add, this); + OnCollectionChanged (e); } finally { @@ -397,7 +399,6 @@ namespace System.Data { /// Adds to the list /// /// The relation to check. - [MonoTODO] protected virtual void AddCore(DataRelation relation) { if (relation == null) { @@ -570,9 +571,9 @@ namespace System.Data { } [MonoTODO] - protected internal virtual void OnCollectionChanging (CollectionChangeEventArgs ccevent) + protected virtual void OnCollectionChanging (CollectionChangeEventArgs ccevent) { - throw new NotImplementedException (); + //throw new NotImplementedException (); } public void Remove (DataRelation relation) @@ -594,6 +595,8 @@ namespace System.Data { if (!(List.Contains(relation))) throw new ArgumentException("Relation doesnot belong to this Collection."); + OnCollectionChanging (CreateCollectionChangeEvent (CollectionChangeAction.Remove)); + RemoveCore (relation); string name = "Relation" + index; if (relation.RelationName == name) @@ -623,7 +626,6 @@ namespace System.Data { Remove(relation); } - [MonoTODO] protected virtual void RemoveCore(DataRelation relation) { // Remove from collection diff --git a/mcs/class/System.Data/System.Data/DataRowCollection.cs b/mcs/class/System.Data/System.Data/DataRowCollection.cs index aad870e8938..2a7076b509a 100644 --- a/mcs/class/System.Data/System.Data/DataRowCollection.cs +++ b/mcs/class/System.Data/System.Data/DataRowCollection.cs @@ -78,13 +78,22 @@ namespace System.Data } } + public override int Count + { + get { + return List.Count; + } + } + +#if !NET_2_0 /// /// This member overrides InternalDataCollectionBase.List /// protected override ArrayList List { get { return base.List; } - } + } +#endif /// /// Adds the specified DataRow to the DataRowCollection object. @@ -109,6 +118,23 @@ namespace System.Data AddInternal(row); } +#if NET_2_0 + public int IndexOf (DataRow row) + { + if (row == null) + return -1; + + int i = 0; + foreach (DataRow dr in this) { + if (dr == row) { + return i; + } + i++; + } + + return -1; + } +#endif internal void AddInternal (DataRow row) { AddInternal (row, DataRowAction.Add); } @@ -199,11 +225,23 @@ namespace System.Data return Find (keys) != null; } +#if NET_2_0 public void CopyTo (DataRow [] array, int index) { CopyTo ((Array) array, index); } + public override void CopyTo (Array array, int index) + { + base.CopyTo (array, index); + } + + public override IEnumerator GetEnumerator () + { + return base.GetEnumerator (); + } +#endif + /// /// Gets the row specified by the primary key value. /// diff --git a/mcs/class/System.Data/System.Data/DataSet.cs b/mcs/class/System.Data/System.Data/DataSet.cs index 9021c888c4c..57d531fdf9b 100644 --- a/mcs/class/System.Data/System.Data/DataSet.cs +++ b/mcs/class/System.Data/System.Data/DataSet.cs @@ -721,8 +721,9 @@ namespace System.Data { #if NET_2_0 public void Load (IDataReader reader, LoadOption loadOption, params DataTable[] tables) { - if (reader == null) - return; + if (reader == null) { + throw new ArgumentNullException ("Value cannot be null. Parameter name: reader"); + } foreach (DataTable dt in tables) { if (dt.DataSet == null || dt.DataSet != this) { throw new ArgumentException ("Table " + dt.TableName + " does not belong to this DataSet."); @@ -734,8 +735,9 @@ namespace System.Data { public void Load (IDataReader reader, LoadOption loadOption, params string[] tables) { - if (reader == null) - return; + if (reader == null) { + throw new ArgumentNullException ("Value cannot be null. Parameter name: reader"); + } foreach (string tableName in tables) { DataTable dt = Tables [tableName]; @@ -750,8 +752,9 @@ namespace System.Data { public void Load (IDataReader reader, LoadOption loadOption, FillErrorEventHandler errorHandler, params DataTable[] tables) { - if (reader == null) - return; + if (reader == null) { + throw new ArgumentNullException ("Value cannot be null. Parameter name: reader"); + } foreach (DataTable dt in tables) { if (dt.DataSet == null || dt.DataSet != this) { throw new ArgumentException ("Table " + dt.TableName + " does not belong to this DataSet."); diff --git a/mcs/class/System.Data/System.Data/DataTable.cs b/mcs/class/System.Data/System.Data/DataTable.cs index 0184e2e8c48..623874f0bf6 100644 --- a/mcs/class/System.Data/System.Data/DataTable.cs +++ b/mcs/class/System.Data/System.Data/DataTable.cs @@ -1692,8 +1692,9 @@ namespace System.Data { /// public void Load (IDataReader reader) { - if (reader == null) - return; + if (reader == null) { + throw new ArgumentNullException ("Value cannot be null. Parameter name: reader"); + } Load (reader, LoadOption.PreserveChanges); } @@ -1704,8 +1705,9 @@ namespace System.Data { /// public void Load (IDataReader reader, LoadOption loadOption) { - if (reader == null) - return; + if (reader == null) { + throw new ArgumentNullException ("Value cannot be null. Parameter name: reader"); + } bool prevEnforceConstr = this.EnforceConstraints; try { this.EnforceConstraints = false; @@ -1726,8 +1728,9 @@ namespace System.Data { public virtual void Load (IDataReader reader, LoadOption loadOption, FillErrorEventHandler errorHandler) { - if (reader == null) - return; + if (reader == null) { + throw new ArgumentNullException ("Value cannot be null. Parameter name: reader"); + } bool prevEnforceConstr = this.EnforceConstraints; try { this.EnforceConstraints = false; @@ -2490,6 +2493,9 @@ namespace System.Data { public void WriteXmlSchema (Stream stream) { + if (TableName == "") { + throw new InvalidOperationException ("Cannot serialize the DataTable. DataTable name is not set."); + } XmlWriterSettings s = GetWriterSettings (); s.OmitXmlDeclaration = false; WriteXmlSchema (XmlWriter.Create (stream, s)); @@ -2497,6 +2503,9 @@ namespace System.Data { public void WriteXmlSchema (TextWriter writer) { + if (TableName == "") { + throw new InvalidOperationException ("Cannot serialize the DataTable. DataTable name is not set."); + } XmlWriterSettings s = GetWriterSettings (); s.OmitXmlDeclaration = false; WriteXmlSchema (XmlWriter.Create (writer, s)); @@ -2504,6 +2513,9 @@ namespace System.Data { public void WriteXmlSchema (XmlWriter writer) { + if (TableName == "") { + throw new InvalidOperationException ("Cannot serialize the DataTable. DataTable name is not set."); + } DataSet ds = DataSet; DataSet tmp = null; try { @@ -2516,7 +2528,12 @@ namespace System.Data { col.Add (this); DataTable [] tables = new DataTable [col.Count]; for (int i = 0; i < col.Count; i++) tables[i] = col[i]; - XmlSchemaWriter.WriteXmlSchema (writer, tables, null, TableName, ds.DataSetName); + string tableName; + if (ds.Namespace == "") + tableName = TableName; + else + tableName = ds.Namespace + "_x003A_" + TableName; + XmlSchemaWriter.WriteXmlSchema (writer, tables, null, tableName, ds.DataSetName); } finally { if (tmp != null) ds.Tables.Remove (this); @@ -2525,6 +2542,12 @@ namespace System.Data { public void WriteXmlSchema (string fileName) { + if (fileName == "") { + throw new ArgumentException ("Empty path name is not legal."); + } + if (TableName == "") { + throw new InvalidOperationException ("Cannot serialize the DataTable. DataTable name is not set."); + } XmlWriter xw = null; try { XmlWriterSettings s = GetWriterSettings (); @@ -2532,13 +2555,17 @@ namespace System.Data { xw = XmlWriter.Create (fileName, s); WriteXmlSchema (xw); } finally { - if (xw != null) + if (xw != null) { xw.Close (); + } } } public void WriteXmlSchema (Stream stream, bool writeHierarchy) { + if (TableName == "") { + throw new InvalidOperationException ("Cannot serialize the DataTable. DataTable name is not set."); + } XmlWriterSettings s = GetWriterSettings (); s.OmitXmlDeclaration = false; WriteXmlSchema (XmlWriter.Create (stream, s), writeHierarchy); @@ -2546,6 +2573,9 @@ namespace System.Data { public void WriteXmlSchema (TextWriter writer, bool writeHierarchy) { + if (TableName == "") { + throw new InvalidOperationException ("Cannot serialize the DataTable. DataTable name is not set."); + } XmlWriterSettings s = GetWriterSettings (); s.OmitXmlDeclaration = false; WriteXmlSchema (XmlWriter.Create (writer, s), writeHierarchy); @@ -2553,6 +2583,9 @@ namespace System.Data { public void WriteXmlSchema (XmlWriter writer, bool writeHierarchy) { + if (TableName == "") { + throw new InvalidOperationException ("Cannot serialize the DataTable. DataTable name is not set."); + } if (writeHierarchy == false) { WriteXmlSchema (writer); } @@ -2566,11 +2599,31 @@ namespace System.Data { } writer.WriteStartDocument (); //XmlSchemaWriter.WriteXmlSchema (ds, writer); - DataTable [] tables = new DataTable [ds.Tables.Count]; - DataRelation [] relations = new DataRelation [ds.Relations.Count]; - for (int i = 0; i < ds.Tables.Count; i++) tables[i] = ds.Tables[i]; - for (int i = 0; i < ds.Relations.Count; i++) relations[i] = ds.Relations[i]; - XmlSchemaWriter.WriteXmlSchema (writer, tables, relations, TableName, ds.DataSetName); + //DataTable [] tables = new DataTable [ds.Tables.Count]; + DataTable [] tables = null; + //DataRelation [] relations = new DataRelation [ds.Relations.Count]; + //for (int i = 0; i < ds.Relations.Count; i++) { + // relations[i] = ds.Relations[i]; + //} + DataRelation [] relations = null; + if (ChildRelations.Count > 0) { + relations = new DataRelation [ChildRelations.Count]; + for (int i = 0; i < ChildRelations.Count; i++) { + relations [i] = ChildRelations [i]; + } + tables = new DataTable [ds.Tables.Count]; + for (int i = 0; i < ds.Tables.Count; i++) tables [i] = ds.Tables [i]; + } else { + tables = new DataTable [1]; + tables [0] = this; + } + + string tableName; + if (ds.Namespace == "") + tableName = TableName; + else + tableName = ds.Namespace + "_x003A_" + TableName; + XmlSchemaWriter.WriteXmlSchema (writer, tables, relations, tableName, ds.DataSetName); } finally { if (tmp != null) ds.Tables.Remove (this); @@ -2580,6 +2633,12 @@ namespace System.Data { public void WriteXmlSchema (string fileName, bool writeHierarchy) { + if (fileName == "") { + throw new ArgumentException ("Empty path name is not legal."); + } + if (TableName == "") { + throw new InvalidOperationException ("Cannot serialize the DataTable. DataTable name is not set."); + } XmlWriter xw = null; try { XmlWriterSettings s = GetWriterSettings (); diff --git a/mcs/class/System.Data/System.Data/XmlSchemaWriter.cs b/mcs/class/System.Data/System.Data/XmlSchemaWriter.cs index 3426c77ea58..2df822231a0 100644 --- a/mcs/class/System.Data/System.Data/XmlSchemaWriter.cs +++ b/mcs/class/System.Data/System.Data/XmlSchemaWriter.cs @@ -213,7 +213,7 @@ namespace System.Data if (dataSetLocale == CultureInfo.CurrentCulture) { w.WriteAttributeString ( XmlConstants.MsdataPrefix, - "UseCurrentCulture", + "UseCurrentLocale", XmlConstants.MsdataNamespace, "true"); } @@ -231,6 +231,7 @@ namespace System.Data w.WriteStartElement ("xs", "complexType", xmlnsxs); w.WriteStartElement ("xs", "choice", xmlnsxs); + w.WriteAttributeString ("minOccurs", "0"); w.WriteAttributeString ("maxOccurs", "unbounded"); foreach (DataTable table in tables) { @@ -336,11 +337,12 @@ namespace System.Data ForeignKeyConstraint fk = c as ForeignKeyConstraint; bool haveConstraint = false; - if (relations != null) + if (relations != null) { foreach (DataRelation r in relations) - if(r.RelationName == fk.ConstraintName) + if (r.RelationName == fk.ConstraintName) haveConstraint = true; - if (fk != null && !haveConstraint) { + } + if (tables.Length > 1 && fk != null && !haveConstraint) { DataRelation rel = new DataRelation (fk.ConstraintName, fk.RelatedColumns, fk.Columns); AddForeignKeys (rel, names, true); -- 2.25.1