Author: anagappan
Date: 2006-12-07 06:31:40 -0500 (Thu, 07 Dec 2006)
New Revision: 69168

Modified:
   trunk/mcs/class/System.Data/System.Data/ChangeLog
   trunk/mcs/class/System.Data/System.Data/DataTable.cs
   trunk/mcs/class/System.Data/System.Data/XmlTableWriter.cs
Log:
2006-12-07  Nagappan A  <[EMAIL PROTECTED]>

        * DataTable.cs (ReadXml): Integrated the implementation of
        ReadXml, patch provided by [EMAIL PROTECTED]



Modified: trunk/mcs/class/System.Data/System.Data/ChangeLog
===================================================================
--- trunk/mcs/class/System.Data/System.Data/ChangeLog   2006-12-07 11:20:12 UTC 
(rev 69167)
+++ trunk/mcs/class/System.Data/System.Data/ChangeLog   2006-12-07 11:31:40 UTC 
(rev 69168)
@@ -1,3 +1,8 @@
+2006-12-07  Nagappan A  <[EMAIL PROTECTED]>
+
+       * DataTable.cs (ReadXml): Integrated the implementation of
+       ReadXml, patch provided by [EMAIL PROTECTED]
+
 2006-12-05  Nagappan A  <[EMAIL PROTECTED]>
 
        * DataTable.cs (WriteXmlSchema): Using XmlTextWriter instead of

Modified: trunk/mcs/class/System.Data/System.Data/DataTable.cs
===================================================================
--- trunk/mcs/class/System.Data/System.Data/DataTable.cs        2006-12-07 
11:20:12 UTC (rev 69167)
+++ trunk/mcs/class/System.Data/System.Data/DataTable.cs        2006-12-07 
11:31:40 UTC (rev 69168)
@@ -1319,6 +1319,9 @@
                                                copyTable = Clone();
                                        DataRow newRow = 
copyTable.NewNotInitializedRow();
                                        row.CopyValuesToRow(newRow);
+#if NET_2_0
+                                       newRow.XmlRowID = row.XmlRowID;
+#endif
                                        copyTable.Rows.AddInternal (newRow);
                                }
                        }
@@ -2017,7 +2020,6 @@
                        return ReadXml (new XmlTextReader(reader));
                }
 
-               [MonoTODO]
                public XmlReadMode ReadXml (XmlReader reader)
                {
                        // The documentation from MS for this method is rather
@@ -2038,10 +2040,106 @@
                        //     msdata:MainDataTable attribute added to the
                        //     schema info to load into the appropriate
                        //     locations.
+                       bool isPartOfDataSet = true;
+                       bool isTableNameBlank = false;
+                       XmlReadMode mode = XmlReadMode.ReadSchema;
+                       DataSet dataSet = null;
+                       DataSet ds = new DataSet ();
 
-                       throw new NotImplementedException ();
+                       reader.MoveToContent ();
+                       if (Columns.Count > 0 && reader.LocalName != 
"diffgram") 
+                               mode = ds.ReadXml (reader);
+                       else if (Columns.Count > 0 && reader.LocalName == 
"diffgram") {
+                                 try {
+                                       if (TableName == String.Empty)
+                                               isTableNameBlank = true;
+                                       if (DataSet == null) {
+                                               isPartOfDataSet = false;
+                                               ds.Tables.Add (this);
+                                               mode = ds.ReadXml (reader);
+                                       } else 
+                                               mode = DataSet.ReadXml (reader);
+                                 } catch (Exception e) {
+                                   if (e.Message == String.Format ("Cannot 
load diffGram. Table '{0}' is missing in the destination dataset",
+                                                                   
reader.LocalName)) {
+                                       mode = XmlReadMode.DiffGram;
+                                       if (isTableNameBlank)
+                                               TableName = String.Empty;
+                                   }
+                                 } finally {
+                                       if (!isPartOfDataSet)
+                                               ds.Tables.Remove (this);
+                                 }
+                                 return mode;
+                       }
+                       else {
+                               mode = ds.ReadXml (reader, 
XmlReadMode.ReadSchema);
+                       }
+                       if (mode == XmlReadMode.InferSchema)
+                               mode = XmlReadMode.IgnoreSchema;
+                       if (DataSet == null) {
+                                 isPartOfDataSet = false;
+                                 dataSet = new DataSet ();
+                                 if (TableName == String.Empty)
+                                       isTableNameBlank = true;
+                                 dataSet.Tables.Add (this);
+                       }
+
+                       DenyXmlResolving (this, ds, mode, isTableNameBlank, 
isPartOfDataSet);
+                       if (Columns.Count > 0 && TableName != ds.Tables 
[0].TableName) {
+                               if (isPartOfDataSet == false)
+                                       dataSet.Tables.Remove (this);
+
+                               if (isTableNameBlank && isPartOfDataSet == 
false)
+                                       TableName = String.Empty;
+                               return mode;
+                       }
+                       else {
+                               TableName = ds.Tables [0].TableName;
+                       }
+
+                       if (!isPartOfDataSet) {
+                               if (Columns.Count > 0) {
+                                       dataSet.Merge (ds, true, 
MissingSchemaAction.Ignore);
+                               } else {
+                                       dataSet.Merge (ds, true, 
MissingSchemaAction.AddWithKey);
+                               }
+                               if (ChildRelations.Count == 0) {
+                                       dataSet.Tables.Remove (this);
+                               } else {
+                                       dataSet.DataSetName = ds.DataSetName;
+                               }
+                       } else {
+                               if (Columns.Count > 0) {
+                                       DataSet.Merge (ds, true, 
MissingSchemaAction.Ignore);
+                               } else {
+                                       DataSet.Merge (ds, true, 
MissingSchemaAction.AddWithKey);
+                               }
+                       }
+                       return mode;
                }
 
+               private void DenyXmlResolving (DataTable table, DataSet ds, 
XmlReadMode mode, bool isTableNameBlank, bool isPartOfDataSet)
+               {
+                       if (ds.Tables.Count == 0 && table.Columns.Count == 0)
+                               throw new InvalidOperationException ("DataTable 
does not support schema inference from XML");
+
+                       if (table.Columns.Count == 0 && ds.Tables [0].TableName 
!= table.TableName && isTableNameBlank == false)
+                               throw new ArgumentException (String.Format 
("DataTable '{0}' does not match to any DataTable in source",
+                                                                           
table.TableName));
+
+                       if (table.Columns.Count > 0 && ds.Tables [0].TableName 
!= table.TableName &&
+                           isTableNameBlank == false && mode == 
XmlReadMode.ReadSchema &&
+                           isPartOfDataSet == false) 
+                               throw new ArgumentException (String.Format 
("DataTable '{0}' does not match to any DataTable in source",
+                                                                           
table.TableName));
+
+                       if (isPartOfDataSet == true && table.Columns.Count > 0 
&&
+                           mode == XmlReadMode.ReadSchema && table.TableName 
!= ds.Tables [0].TableName)
+                               throw new ArgumentException (String.Format 
("DataTable '{0}' does not match to any DataTable in source",
+                                                                           
table.TableName));
+               }
+
                public void ReadXmlSchema (Stream stream)
                {
                        ReadXmlSchema (new XmlTextReader (stream));
@@ -2066,6 +2164,9 @@
 
                public void ReadXmlSchema (XmlReader reader)
                {
+                       if (this.Columns.Count > 0)
+                               return;
+
                        DataSet ds = new DataSet ();
                        new XmlSchemaDataImporter (ds, reader).Process ();
                        DataTable target = null;
@@ -2445,21 +2546,19 @@
                        //   is a wrapper dataset called DocumentElement.
                        
                        // Generate a list of tables to write.
-                       List<DataTable> tables = new List<DataTable>(); 
+                       List <DataTable> tables = new List <DataTable> ();
                        if (writeHierarchy == false)
-                               tables.Add(this);
+                               tables.Add (this);
                        else
-                               FindAllChildren(tables, this);
+                               FindAllChildren (tables, this);
 
                        // If we're in a DataSet, generate a list of relations 
to write.
-                       List<DataRelation> relations = new List<DataRelation>();
-                       if (DataSet != null)
-                       {
-                               foreach(DataRelation relation in 
DataSet.Relations)
-                               {
-                                       
if(tables.Contains(relation.ParentTable) &&
-                                          tables.Contains(relation.ChildTable))
-                                               relations.Add(relation);
+                       List <DataRelation> relations = new List <DataRelation> 
();
+                       if (DataSet != null) {
+                               foreach (DataRelation relation in 
DataSet.Relations) {
+                                       if (tables.Contains 
(relation.ParentTable) &&
+                                          tables.Contains 
(relation.ChildTable))
+                                               relations.Add (relation);
                                }
                        }
 

Modified: trunk/mcs/class/System.Data/System.Data/XmlTableWriter.cs
===================================================================
--- trunk/mcs/class/System.Data/System.Data/XmlTableWriter.cs   2006-12-07 
11:20:12 UTC (rev 69167)
+++ trunk/mcs/class/System.Data/System.Data/XmlTableWriter.cs   2006-12-07 
11:31:40 UTC (rev 69168)
@@ -73,8 +73,9 @@
                        List<DataTable> changedTables = new List<DataTable>();
                        foreach (DataTable table in tables) {
                                DataTable changed = 
table.GetChanges(DataRowState.Modified | DataRowState.Deleted);
-                               if (changed != null && changed.Rows.Count > 0)
+                               if (changed != null && changed.Rows.Count > 0) {
                                        changedTables.Add(changed);
+                               }
                        }
                        if (changedTables.Count > 0) {
                                DataSet.WriteStartElement(writer, 
XmlWriteMode.DiffGram, XmlConstants.DiffgrNamespace, XmlConstants.DiffgrPrefix, 
"before");

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to