Author: anagappan
Date: 2006-10-20 11:14:29 -0400 (Fri, 20 Oct 2006)
New Revision: 66830
Added:
trunk/mcs/class/System.Data/System.Data/XmlTableWriter.cs
Modified:
trunk/mcs/class/System.Data/System.Data/ChangeLog
trunk/mcs/class/System.Data/System.Data/DataSet.cs
trunk/mcs/class/System.Data/System.Data/DataTable.cs
trunk/mcs/class/System.Data/System.Data/ForeignKeyConstraint.cs
trunk/mcs/class/System.Data/System.Data/XmlSchemaWriter.cs
Log:
2006-10-18 Nagappan A <[EMAIL PROTECTED]>
* ForeignKeyConstraint.cs (_validateColumns): Parent and child
columns can't be the same column - Exception, bug # 79689
2006-10-06 Patrick Earl <[EMAIL PROTECTED]>
* DataTable.cs, XmlTableWriter.cs, XmlSchemaWriter.cs, DataSet.cs:
Implemented DataTable.WriteXml
Modified: trunk/mcs/class/System.Data/System.Data/ChangeLog
===================================================================
--- trunk/mcs/class/System.Data/System.Data/ChangeLog 2006-10-20 15:10:18 UTC
(rev 66829)
+++ trunk/mcs/class/System.Data/System.Data/ChangeLog 2006-10-20 15:14:29 UTC
(rev 66830)
@@ -1,3 +1,8 @@
+2006-10-18 Nagappan A <[EMAIL PROTECTED]>
+
+ * ForeignKeyConstraint.cs (_validateColumns): Parent and child
+ columns can't be the same column - Exception, bug # 79689
+
2006-10-13 Nagappan A <[EMAIL PROTECTED]>
* DataTable.cs (DeserializeConstraints): Fine tuned the
@@ -7,6 +12,11 @@
#79233. DuplicateNameException when two relations for different
DataTables in DataSet are defined
+2006-10-06 Patrick Earl <[EMAIL PROTECTED]>
+
+ * DataTable.cs, XmlTableWriter.cs, XmlSchemaWriter.cs, DataSet.cs:
+ Implemented DataTable.WriteXml
+
2006-09-26 Nagappan A <[EMAIL PROTECTED]>
* DataTable.cs, DataSet.cs, DataColumn.cs, Constraint.cs,
Modified: trunk/mcs/class/System.Data/System.Data/DataSet.cs
===================================================================
--- trunk/mcs/class/System.Data/System.Data/DataSet.cs 2006-10-20 15:10:18 UTC
(rev 66829)
+++ trunk/mcs/class/System.Data/System.Data/DataSet.cs 2006-10-20 15:14:29 UTC
(rev 66830)
@@ -45,7 +45,9 @@
using System.Threading;
using System.IO;
using System.Runtime.Serialization;
+#if NET_2_0
using System.Runtime.Serialization.Formatters.Binary;
+#endif
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
@@ -1538,29 +1540,33 @@
WriteTable ( writer, table, mode, version);
}
- private void WriteTable (XmlWriter writer, DataTable table,
XmlWriteMode mode, DataRowVersion version)
+ internal static void WriteTable (XmlWriter writer, DataTable
table, XmlWriteMode mode, DataRowVersion version)
{
DataRow[] rows = table.NewRowArray(table.Rows.Count);
table.Rows.CopyTo (rows, 0);
WriteTable (writer, rows, mode, version, true);
}
- private void WriteTable (XmlWriter writer,
+ internal static void WriteTable (XmlWriter writer,
DataRow [] rows,
XmlWriteMode mode,
DataRowVersion version, bool skipIfNested)
{
+ if (rows.Length == 0) return;
+ DataTable table = rows[0].Table;
+
+ if (table.TableName == null || table.TableName == "")
+ throw new InvalidOperationException("Cannot
serialize the DataTable. DataTable name is not set.");
+
//The columns can be attributes, hidden, elements, or
simple content
//There can be 0-1 simple content cols or 0-* elements
System.Collections.ArrayList atts;
System.Collections.ArrayList elements;
DataColumn simple = null;
- if (rows.Length == 0) return;
- DataTable table = rows[0].Table;
SplitColumns (table, out atts, out elements, out
simple);
//sort out the namespacing
- string nspc = table.Namespace.Length > 0 ?
table.Namespace : Namespace;
+ string nspc = (table.Namespace.Length > 0 ||
table.DataSet == null) ? table.Namespace : table.DataSet.Namespace;
int relationCount = table.ParentRelations.Count;
DataRelation oneRel = relationCount == 1 ?
table.ParentRelations [0] : null;
@@ -1628,7 +1634,7 @@
}
- private void WriteColumnAsElement (XmlWriter writer,
XmlWriteMode mode, DataColumn col, DataRow row, DataRowVersion version)
+ internal static void WriteColumnAsElement (XmlWriter writer,
XmlWriteMode mode, DataColumn col, DataRow row, DataRowVersion version)
{
string colnspc = null;
object rowObject = row [col, version];
@@ -1645,16 +1651,16 @@
writer.WriteEndElement ();
}
- private void WriteColumnAsAttribute (XmlWriter writer,
XmlWriteMode mode, DataColumn col, DataRow row, DataRowVersion version)
+ internal static void WriteColumnAsAttribute (XmlWriter writer,
XmlWriteMode mode, DataColumn col, DataRow row, DataRowVersion version)
{
if (!row.IsNull (col))
WriteAttributeString (writer, mode,
col.Namespace, col.Prefix, XmlHelper.Encode (col.ColumnName), WriteObjectXml
(row[col, version]));
}
- private void WriteTableElement (XmlWriter writer, XmlWriteMode
mode, DataTable table, DataRow row, DataRowVersion version)
+ internal static void WriteTableElement (XmlWriter writer,
XmlWriteMode mode, DataTable table, DataRow row, DataRowVersion version)
{
//sort out the namespacing
- string nspc = table.Namespace.Length > 0 ?
table.Namespace : Namespace;
+ string nspc = (table.Namespace.Length > 0 ||
table.DataSet == null) ? table.Namespace : table.DataSet.Namespace;
WriteStartElement (writer, mode, nspc, table.Prefix,
XmlHelper.Encode (table.TableName));
@@ -1672,12 +1678,12 @@
}
}
- private void WriteStartElement (XmlWriter writer, XmlWriteMode
mode, string nspc, string prefix, string name)
+ internal static void WriteStartElement (XmlWriter writer,
XmlWriteMode mode, string nspc, string prefix, string name)
{
writer.WriteStartElement (prefix, name, nspc);
}
- private void WriteAttributeString (XmlWriter writer,
XmlWriteMode mode, string nspc, string prefix, string name, string stringValue)
+ internal static void WriteAttributeString (XmlWriter writer,
XmlWriteMode mode, string nspc, string prefix, string name, string stringValue)
{
switch ( mode) {
case XmlWriteMode.WriteSchema:
@@ -1695,7 +1701,7 @@
internal void WriteIndividualTableContent (XmlWriter writer,
DataTable table, XmlWriteMode mode)
{
if (mode == XmlWriteMode.DiffGram) {
- SetTableRowsID (table);
+ table.SetRowsID ();
WriteDiffGramElement (writer);
}
@@ -1760,7 +1766,7 @@
}
}
- private void WriteDiffGramElement(XmlWriter writer)
+ internal static void WriteDiffGramElement(XmlWriter writer)
{
WriteStartElement (writer, XmlWriteMode.DiffGram,
XmlConstants.DiffgrNamespace, XmlConstants.DiffgrPrefix, "diffgram");
WriteAttributeString(writer, XmlWriteMode.DiffGram,
null, "xmlns", XmlConstants.MsdataPrefix, XmlConstants.MsdataNamespace);
@@ -1768,18 +1774,10 @@
private void SetRowsID()
{
- foreach (DataTable Table in Tables)
- SetTableRowsID (Table);
+ foreach (DataTable table in Tables)
+ table.SetRowsID();
}
- private void SetTableRowsID (DataTable Table)
- {
- int dataRowID = 0;
- foreach (DataRow Row in Table.Rows) {
- Row.XmlRowID = dataRowID;
- dataRowID++;
- }
- }
#endregion //Private Xml Serialisation
}
}
Modified: trunk/mcs/class/System.Data/System.Data/DataTable.cs
===================================================================
--- trunk/mcs/class/System.Data/System.Data/DataTable.cs 2006-10-20
15:10:18 UTC (rev 66829)
+++ trunk/mcs/class/System.Data/System.Data/DataTable.cs 2006-10-20
15:14:29 UTC (rev 66830)
@@ -43,6 +43,9 @@
using System;
using System.Data.Common;
using System.Collections;
+#if NET_2_0
+using System.Collections.Generic;
+#endif
using System.ComponentModel;
using System.Globalization;
using System.IO;
@@ -1920,10 +1923,49 @@
}
#if NET_2_0
+ public XmlReadMode ReadXml (Stream stream)
+ {
+ return ReadXml (new XmlTextReader(stream, null));
+ }
+
+ public XmlReadMode ReadXml (string fileName)
+ {
+ XmlReader reader = new XmlTextReader(fileName);
+ try {
+ return ReadXml (reader);
+ } finally {
+ reader.Close();
+ }
+ }
+
+ public XmlReadMode ReadXml (TextReader reader)
+ {
+ return ReadXml (new XmlTextReader(reader));
+ }
+
[MonoTODO]
- XmlReadMode ReadXml (Stream stream)
+ public XmlReadMode ReadXml (XmlReader reader)
{
- throw new NotImplementedException ();
+ // The documentation from MS for this method is rather
+ // poor. The following cases have been observed
+ // during testing:
+ //
+ // Reading a table from XML may create a DataSet to
+ // store child tables.
+ //
+ // If the table has at least one column present,
+ // we do not require the schema to be present in
+ // the xml. If the table has no columns, neither
+ // regular data nor diffgrams will be read, but
+ // will throw an error indicating that schema
+ // will not be inferred.
+ //
+ // We will likely need to take advantage of the
+ // msdata:MainDataTable attribute added to the
+ // schema info to load into the appropriate
+ // locations.
+
+ throw new NotImplementedException();
}
public void ReadXmlSchema (Stream stream)
@@ -2235,57 +2277,158 @@
{
XmlWriterSettings s = new XmlWriterSettings ();
s.Indent = true;
+ s.OmitXmlDeclaration = true;
return s;
}
public void WriteXml (Stream stream)
{
- WriteXml (stream, XmlWriteMode.IgnoreSchema);
+ WriteXml (stream, XmlWriteMode.IgnoreSchema, false);
}
public void WriteXml (TextWriter writer)
{
- WriteXml (writer, XmlWriteMode.IgnoreSchema);
+ WriteXml (writer, XmlWriteMode.IgnoreSchema, false);
}
public void WriteXml (XmlWriter writer)
{
- WriteXml (writer, XmlWriteMode.IgnoreSchema);
+ WriteXml (writer, XmlWriteMode.IgnoreSchema, false);
}
public void WriteXml (string fileName)
{
- WriteXml (fileName, XmlWriteMode.IgnoreSchema);
+ WriteXml (fileName, XmlWriteMode.IgnoreSchema, false);
}
public void WriteXml (Stream stream, XmlWriteMode mode)
{
- WriteXml (XmlWriter.Create (stream, GetWriterSettings
()), mode);
+ WriteXml (stream, mode, false);
}
public void WriteXml (TextWriter writer, XmlWriteMode mode)
{
- WriteXml (XmlWriter.Create (writer, GetWriterSettings
()), mode);
+ WriteXml (writer, mode, false);
}
- [MonoTODO]
public void WriteXml (XmlWriter writer, XmlWriteMode mode)
{
- throw new NotImplementedException ();
+ WriteXml (writer, mode, false);
}
public void WriteXml (string fileName, XmlWriteMode mode)
{
+ WriteXml (fileName, mode, false);
+ }
+
+ public void WriteXml (Stream stream, bool writeHierarchy)
+ {
+ WriteXml (stream, XmlWriteMode.IgnoreSchema,
writeHierarchy);
+ }
+
+ public void WriteXml (string fileName, bool writeHierarchy)
+ {
+ WriteXml (fileName, XmlWriteMode.IgnoreSchema,
writeHierarchy);
+ }
+
+ public void WriteXml (TextWriter writer, bool writeHierarchy)
+ {
+ WriteXml (writer, XmlWriteMode.IgnoreSchema,
writeHierarchy);
+ }
+
+ public void WriteXml (XmlWriter writer, bool writeHierarchy)
+ {
+ WriteXml (writer, XmlWriteMode.IgnoreSchema,
writeHierarchy);
+ }
+
+ public void WriteXml (Stream stream, XmlWriteMode mode, bool
writeHierarchy)
+ {
+ WriteXml (XmlWriter.Create (stream, GetWriterSettings
()), mode, writeHierarchy);
+ }
+
+ public void WriteXml (string fileName, XmlWriteMode mode, bool
writeHierarchy)
+ {
XmlWriter xw = null;
try {
xw = XmlWriter.Create (fileName,
GetWriterSettings ());
- WriteXml (xw, mode);
+ WriteXml (xw, mode, writeHierarchy);
} finally {
if (xw != null)
xw.Close ();
}
}
+ public void WriteXml (TextWriter writer, XmlWriteMode mode,
bool writeHierarchy)
+ {
+ WriteXml (XmlWriter.Create (writer, GetWriterSettings
()), mode, writeHierarchy);
+ }
+
+ public void WriteXml (XmlWriter writer, XmlWriteMode mode, bool
writeHierarchy)
+ {
+ // If we're in mode XmlWriteMode.WriteSchema, we need
to output an extra
+ // msdata:MainDataTable attribute that wouldn't
normally be part of the
+ // DataSet WriteXml output.
+ //
+ // For the writeHierarchy == true case, we write what
would be output by
+ // a DataSet write, but we limit ourselves to our table
and its descendants.
+ //
+ // For the writeHierarchy == false case, we write what
would be output by
+ // a DataSet write, but we limit ourselves to this
table.
+ //
+ // If the table is not in a DataSet, we follow the
following behaviour:
+ // For WriteSchema cases, we do a write as if there
is a wrapper
+ // dataset called NewDataSet.
+ // For IgnoreSchema or DiffGram cases, we do a write
as if there
+ // is a wrapper dataset called DocumentElement.
+
+ // Generate a list of tables to write.
+ List<DataTable> tables = new List<DataTable>();
+ if (writeHierarchy == false)
+ tables.Add(this);
+ else
+ 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);
+ }
+ }
+
+ // Add the msdata:MainDataTable info if we're writing
schema data.
+ string mainDataTable = null;
+ if (mode == XmlWriteMode.WriteSchema)
+ mainDataTable = this.TableName;
+
+ // Figure out the DataSet name.
+ string dataSetName = null;
+ if (DataSet != null)
+ dataSetName = DataSet.DataSetName;
+ else if (DataSet == null && mode ==
XmlWriteMode.WriteSchema)
+ dataSetName = "NewDataSet";
+ else
+ dataSetName = "DocumentElement";
+
+ XmlTableWriter.WriteTables(writer, mode, tables,
relations, mainDataTable, dataSetName);
+ }
+
+ private void FindAllChildren(List<DataTable> list, DataTable
root)
+ {
+ if (!list.Contains(root))
+ {
+ list.Add(root);
+ foreach (DataRelation relation in
root.ChildRelations)
+ {
+ FindAllChildren(list,
relation.ChildTable);
+ }
+ }
+ }
+
public void WriteXmlSchema (Stream stream)
{
WriteXmlSchema (XmlWriter.Create (stream,
GetWriterSettings ()));
@@ -2572,5 +2715,14 @@
internal void ResetPropertyDescriptorsCache() {
_propertyDescriptorsCache = null;
}
+
+ internal void SetRowsID()
+ {
+ int dataRowID = 0;
+ foreach (DataRow row in Rows) {
+ row.XmlRowID = dataRowID;
+ dataRowID++;
+ }
+ }
}
}
Modified: trunk/mcs/class/System.Data/System.Data/ForeignKeyConstraint.cs
===================================================================
--- trunk/mcs/class/System.Data/System.Data/ForeignKeyConstraint.cs
2006-10-20 15:10:18 UTC (rev 66829)
+++ trunk/mcs/class/System.Data/System.Data/ForeignKeyConstraint.cs
2006-10-20 15:14:29 UTC (rev 66830)
@@ -248,14 +248,16 @@
}
+ int identicalCols = 0;
for (int i = 0; i < parentColumns.Length; i++)
{
DataColumn pc = parentColumns[i];
DataColumn cc = childColumns[i];
- //Can't be the same column
- if (pc == cc)
- throw new
InvalidOperationException("Parent and child columns can't be the same column.");
+ if (pc == cc) {
+ identicalCols++;
+ continue;
+ }
if (!pc.DataTypeMatches (cc)) {
//LAMESPEC: spec says throw
InvalidConstraintException
@@ -264,6 +266,8 @@
+ " column.");
}
}
+ if (identicalCols == parentColumns.Length)
+ throw new InvalidOperationException ("Property
not accessible because 'ParentKey and ChildKey are identical.'.");
}
Modified: trunk/mcs/class/System.Data/System.Data/XmlSchemaWriter.cs
===================================================================
--- trunk/mcs/class/System.Data/System.Data/XmlSchemaWriter.cs 2006-10-20
15:10:18 UTC (rev 66829)
+++ trunk/mcs/class/System.Data/System.Data/XmlSchemaWriter.cs 2006-10-20
15:14:29 UTC (rev 66830)
@@ -64,16 +64,50 @@
XmlWriter writer, DataTableCollection tables,
DataRelationCollection relations)
{
- ds = dataset;
+ dataSetName = dataset.DataSetName;
+ dataSetNamespace = dataset.Namespace;
+ dataSetLocale = dataset.Locale;
+ dataSetProperties = dataset.ExtendedProperties;
w = writer;
+ if (tables != null) {
+ this.tables = new DataTable[tables.Count];
+ for(int i=0;i<tables.Count;i++) this.tables[i]
= tables[i];
+ }
+ if (relations != null) {
+ this.relations = new
DataRelation[relations.Count];
+ for(int i=0;i<relations.Count;i++)
this.relations[i] = relations[i];
+ }
+ }
+
+ public XmlSchemaWriter (XmlWriter writer,
+ DataTable[] tables,
+ DataRelation[] relations,
+ string mainDataTable,
+ string dataSetName)
+ {
+ w = writer;
this.tables = tables;
this.relations = relations;
+ this.mainDataTable = mainDataTable;
+ this.dataSetName = dataSetName;
+ this.dataSetProperties = new PropertyCollection();
+ if (tables[0].DataSet != null) {
+ dataSetNamespace = tables[0].DataSet.Namespace;
+ dataSetLocale = tables[0].DataSet.Locale;
+ } else {
+ dataSetNamespace = tables[0].Namespace;
+ dataSetLocale = tables[0].Locale;
+ }
}
- DataSet ds;
XmlWriter w;
- DataTableCollection tables;
- DataRelationCollection relations;
+ DataTable[] tables;
+ DataRelation[] relations;
+ string mainDataTable;
+ string dataSetName;
+ string dataSetNamespace;
+ PropertyCollection dataSetProperties;
+ CultureInfo dataSetLocale;
ArrayList globalTypeTables = new ArrayList ();
Hashtable additionalNamespaces = new Hashtable ();
@@ -81,7 +115,7 @@
ArrayList annotation = new ArrayList ();
public string ConstraintPrefix {
- get { return ds.Namespace != String.Empty ?
XmlConstants.TnsPrefix + ':' : String.Empty; }
+ get { return dataSetNamespace != String.Empty ?
XmlConstants.TnsPrefix + ':' : String.Empty; }
}
// the whole DataSet
@@ -99,18 +133,18 @@
}
w.WriteStartElement ("xs", "schema", xmlnsxs);
- w.WriteAttributeString ("id", XmlHelper.Encode
(ds.DataSetName));
+ w.WriteAttributeString ("id", XmlHelper.Encode
(dataSetName));
- if (ds.Namespace != String.Empty) {
+ if (dataSetNamespace != String.Empty) {
w.WriteAttributeString ("targetNamespace",
- ds.Namespace);
+ dataSetNamespace);
w.WriteAttributeString (
"xmlns",
XmlConstants.TnsPrefix,
XmlConstants.XmlnsNS,
- ds.Namespace);
+ dataSetNamespace);
}
- w.WriteAttributeString ("xmlns", ds.Namespace);
+ w.WriteAttributeString ("xmlns", dataSetNamespace);
w.WriteAttributeString ("xmlns", "xs",
XmlConstants.XmlnsNS, xmlnsxs);
@@ -125,7 +159,7 @@
XmlConstants.XmlnsNS,
XmlConstants.MspropNamespace);
- if (ds.Namespace != String.Empty) {
+ if (dataSetNamespace != String.Empty) {
w.WriteAttributeString ("attributeFormDefault",
"qualified");
w.WriteAttributeString ("elementFormDefault",
"qualified");
}
@@ -156,12 +190,19 @@
private void WriteDataSetElement ()
{
w.WriteStartElement ("xs", "element", xmlnsxs);
- w.WriteAttributeString ("name", XmlHelper.Encode
(ds.DataSetName));
+ w.WriteAttributeString ("name", XmlHelper.Encode
(dataSetName));
w.WriteAttributeString (XmlConstants.MsdataPrefix,
"IsDataSet", XmlConstants.MsdataNamespace,
"true");
+
+ if(mainDataTable != null && mainDataTable != "")
+ w.WriteAttributeString (
+ XmlConstants.MsdataPrefix,
+ "MainDataTable",
+ XmlConstants.MsdataNamespace,
+ mainDataTable);
#if NET_2_0
- if (ds.Locale == CultureInfo.CurrentCulture) {
+ if (dataSetLocale == CultureInfo.CurrentCulture) {
w.WriteAttributeString (
XmlConstants.MsdataPrefix,
"UseCurrentCulture",
@@ -175,10 +216,10 @@
XmlConstants.MsdataPrefix,
"Locale",
XmlConstants.MsdataNamespace,
- ds.Locale.Name);
+ dataSetLocale.Name);
}
- AddExtendedPropertyAttributes (ds.ExtendedProperties);
+ AddExtendedPropertyAttributes (dataSetProperties);
w.WriteStartElement ("xs", "complexType", xmlnsxs);
w.WriteStartElement ("xs", "choice", xmlnsxs);
@@ -194,7 +235,7 @@
}
if (isTopLevel) {
- if (ds.Namespace != table.Namespace) {
+ if (dataSetNamespace !=
table.Namespace) {
// <xs:element ref="X:y" />
w.WriteStartElement ("xs",
"element",
@@ -286,7 +327,12 @@
}
ForeignKeyConstraint fk = c as
ForeignKeyConstraint;
- if (fk != null && (relations == null ||
!(relations.Contains (fk.ConstraintName)))) {
+ bool haveConstraint = false;
+ if (relations != null)
+ foreach (DataRelation r in
relations)
+ if(r.RelationName ==
fk.ConstraintName)
+ haveConstraint
= true;
+ if (fk != null && !haveConstraint) {
DataRelation rel = new
DataRelation (fk.ConstraintName,
fk.RelatedColumns, fk.Columns);
AddForeignKeys (rel, names,
true);
@@ -399,12 +445,12 @@
// first try to find the concatenated name. If we
didn't find it - use constraint name.
if (names.Contains (concatName)) {
w.WriteStartAttribute ("refer", String.Empty);
- w.WriteQualifiedName (concatName, ds.Namespace);
+ w.WriteQualifiedName (concatName,
dataSetNamespace);
w.WriteEndAttribute ();
}
else {
w.WriteStartAttribute ("refer", String.Empty);
- w.WriteQualifiedName (XmlHelper.Encode
(uqConst.ConstraintName), ds.Namespace);
+ w.WriteQualifiedName (XmlHelper.Encode
(uqConst.ConstraintName), dataSetNamespace);
w.WriteEndAttribute ();
}
@@ -445,10 +491,10 @@
// ExtendedProperties
private bool CheckExtendedPropertyExists (
- DataTableCollection tables,
- DataRelationCollection relations)
+ DataTable[] tables,
+ DataRelation[] relations)
{
- if (ds.ExtendedProperties.Count > 0)
+ if (dataSetProperties.Count > 0)
return true;
foreach (DataTable dt in tables) {
if (dt.ExtendedProperties.Count > 0)
@@ -640,7 +686,7 @@
private void WriteChildRelations (DataRelation rel)
{
- if (rel.ChildTable.Namespace != ds.Namespace) {
+ if (rel.ChildTable.Namespace != dataSetNamespace) {
w.WriteStartElement ("xs", "element", xmlnsxs);
w.WriteStartAttribute ("ref", String.Empty);
w.WriteQualifiedName (
@@ -734,8 +780,8 @@
{
if (ns == String.Empty)
return;
- if (ds.Namespace != ns) {
- if (names [prefix] != ns) {
+ if (dataSetNamespace != ns) {
+ if ((string)names [prefix] != ns) {
for (int i = 1; i < int.MaxValue; i++) {
string p = "app" + i;
if (names [p] == null) {
Added: trunk/mcs/class/System.Data/System.Data/XmlTableWriter.cs
===================================================================
--- trunk/mcs/class/System.Data/System.Data/XmlTableWriter.cs 2006-10-20
15:10:18 UTC (rev 66829)
+++ trunk/mcs/class/System.Data/System.Data/XmlTableWriter.cs 2006-10-20
15:14:29 UTC (rev 66830)
@@ -0,0 +1,97 @@
+//
+// System.Data/XmlTableWriter.cs
+//
+// Author:
+// Patrick Earl <[EMAIL PROTECTED]>
+//
+// Copyright (c) 2006, Patrick Earl
+//
+// 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.
+
+#if NET_2_0
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Xml;
+
+internal class XmlTableWriter {
+ // This method is modelled after the DataSet's WriteXml functionality.
+ internal static void WriteTables(XmlWriter writer,
+ XmlWriteMode mode,
+ List<DataTable> tables,
+ List<DataRelation> relations,
+ string mainDataTable,
+ string dataSetName)
+ {
+ if (mode == XmlWriteMode.DiffGram) {
+ foreach (DataTable table in tables)
+ table.SetRowsID();
+ DataSet.WriteDiffGramElement(writer);
+ }
+
+ bool shouldOutputContent = (mode != XmlWriteMode.DiffGram);
+ for (int n = 0; n < tables.Count && !shouldOutputContent; n++)
+ shouldOutputContent = tables[n].Rows.Count > 0;
+
+ if (shouldOutputContent) {
+ // We assume that tables[0] is the main table being
written.
+ // We happen to know that the code above us does things
that way.
+ DataSet.WriteStartElement(writer, mode,
tables[0].Namespace, tables[0].Prefix, XmlHelper.Encode(dataSetName));
+
+ if (mode == XmlWriteMode.WriteSchema) {
+ new XmlSchemaWriter(writer,
+ tables.ToArray(),
+ relations.ToArray(),
+ mainDataTable,
+ dataSetName
+ ).WriteSchema();
+ }
+
+ WriteTableList (writer, mode, tables,
DataRowVersion.Default);
+
+ writer.WriteEndElement();
+ }
+
+ if (mode == XmlWriteMode.DiffGram) {
+ 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)
+ changedTables.Add(changed);
+ }
+ if (changedTables.Count > 0) {
+ DataSet.WriteStartElement(writer,
XmlWriteMode.DiffGram, XmlConstants.DiffgrNamespace, XmlConstants.DiffgrPrefix,
"before");
+ WriteTableList (writer, mode, changedTables,
DataRowVersion.Original);
+ writer.WriteEndElement();
+ }
+
+ writer.WriteEndElement(); // diffgr:diffgram
+ }
+
+ writer.Flush();
+ }
+
+ internal static void WriteTableList(XmlWriter writer, XmlWriteMode
mode, List<DataTable> tables, DataRowVersion version)
+ {
+ foreach (DataTable table in tables)
+ DataSet.WriteTable(writer, table, mode, version);
+ }
+}
+#endif
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches