[Mono-bugs] [Bug 68972][Nor] New - XSD creates buggy typed datasets
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Mon, 1 Nov 2004 07:48:15 -0500 (EST)
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by juergen@cis-comsoft.de.
http://bugzilla.ximian.com/show_bug.cgi?id=68972
--- shadow/68972 2004-11-01 07:48:15.000000000 -0500
+++ shadow/68972.tmp.19584 2004-11-01 07:48:15.000000000 -0500
@@ -0,0 +1,164 @@
+Bug#: 68972
+Product: Mono: Compilers
+Version: unspecified
+OS: GNU/Linux [Other]
+OS Details: Ubuntu 4.10
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: XSD
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: juergen@cis-comsoft.de
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: XSD creates buggy typed datasets
+
+Description of Problem:
+
+XSD creates strongly typed DataSets that throw exceptions when accessing
+the column-properties of datarows.
+
+Steps to reproduce the problem:
+step 1.
+Create Database on PostgreSQL
+Use this as input for psql:
+
+CREATE DATABASE test;
+
+\c test
+
+CREATE TABLE "simple" (
+ nr smallint,
+ name character varying(10)
+);
+
+COPY "simple" (nr, name) FROM stdin;
+1 Peter
+2 Paul
+3 Mary
+\.
+
+--### end of psql-input
+
+step 2.
+//Create test_ds.xsd
+
+using System;
+using System.Data;
+using System.Data.Common;
+using Npgsql;
+
+class MainClass
+{
+ public static void Main(string[] args)
+ {
+ string connStr="Server=localhost;User ID=juergen;Database=test";
+
+ NpgsqlConnection conn = new Npgsql.NpgsqlConnection(connStr);
+ conn.Open();
+ DataSet ds = new DataSet("testDataSet");
+ NpgsqlDataAdapter da = new NpgsqlDataAdapter("SELECT * FROM simple
+WHERE 1=0;", conn);
+ Console.WriteLine(da.Fill(ds, "simple"));
+ ds.WriteXmlSchema("test_ds.xsd");
+ conn.Close();
+ }
+}
+
+#######
+output is test_ds.xsd:
+
+<?xml version="1.0" standalone="yes"?>
+<xs:schema xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
+id="testDataSet" xmlns:xs="http://www.w3.org/2001/XMLSchema">
+ <xs:element name="testDataSet" msdata:IsDataSet="true" msdata:Locale="de-DE">
+ <xs:complexType>
+ <xs:choice maxOccurs="unbounded">
+ <xs:element name="simple">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element minOccurs="0" name="nr" type="xs:short" />
+ <xs:element minOccurs="0" name="name" type="xs:string" />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ </xs:choice>
+ </xs:complexType>
+ </xs:element>
+</xs:schema>
+
+step 3.
+Create source for test_ds.c
+
+xsd test_ds.xsd /dataset
+
+step 4.
+Use test_ds:
+
+using System;
+using System.Data;
+using Npgsql;
+
+class MainClass
+{
+ public static void Main(string[] args)
+ {
+ string connStr="Server=localhost;User ID=juergen;Database=test";
+
+ NpgsqlConnection conn;
+ Schemas.testDataSet tds = new Schemas.testDataSet();
+
+ conn = new NpgsqlConnection(connStr);
+ NpgsqlDataAdapter da = new NpgsqlDataAdapter("SELECT * FROM
+simple;", (NpgsqlConnection)conn);
+
+ Console.WriteLine(da.Fill(tds.simple));
+
+ Console.WriteLine(tds.simple[0].name);
+ Console.WriteLine(tds.simple[0].nr);
+
+ conn.Close();
+ }
+}
+
+Actual Results:
+Exceptions accessing tds.simple[0].name and tds.simple[0].nr
+
+Expected Results:
+No exceptions ;-)
+
+How often does this happen?
+every time
+
+Additional Information:
+There are 2 places in the get-accessor of the column properties of datarows
+that throw exceptions. Look at comments
+
+public virtual short nr {
+ get {
+ // next line (XSD-created) throws NullReferenceException because
+ // InitializeFields for the table is never called and so the
+ // column-variables aren't set. Calling it after InitializeClass
+ // in the table-constructor makes this work (don't know if that's
+ // the right place to call it...).
+ object ret = this[this.table.nrColumn];
+ if ((ret == System.DBNull.Value)) {
+ throw new System.Data.StrongTypingException("Cannot get strong
+typed value since it is DB null.", null);
+ }
+ else {
+ // next line (XSD-created) throws InvalidCastException
+ // the equivalent for strings seems to work
+ return ((short)(ret));
+
+ // this works
+ return Convert.ToInt16(ret);
+ }
+ }
+ set {
+ this[this.table.nrColumn] = value;
+ }
+}