[Mono-bugs] [Bug 67757][Maj] New - DataTable.Add does not work if a field is "NOT NULL" but set to auto_increment
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Thu, 7 Oct 2004 09:24:48 -0400 (EDT)
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 afaillace@etnoteam.it.
http://bugzilla.ximian.com/show_bug.cgi?id=67757
--- shadow/67757 2004-10-07 09:24:48.000000000 -0400
+++ shadow/67757.tmp.4279 2004-10-07 09:24:48.000000000 -0400
@@ -0,0 +1,167 @@
+Bug#: 67757
+Product: Mono: Class Libraries
+Version: unspecified
+OS: SuSE 8.0
+OS Details:
+Status: NEW
+Resolution:
+Severity: 080 Two weeks
+Priority: Major
+Component: Sys.Data
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: afaillace@etnoteam.it
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Summary: DataTable.Add does not work if a field is "NOT NULL" but set to auto_increment
+
+Description of Problem:
+
+If i defined a NOT NULL , auto_increment field (such as an id field)
+in Add method the DataTable throws an exception:
+System.Data.NoNullAllowedException Column 'id' does not allow nulls.
+(the code that rises the exception is in UniqueConstraint.cs)
+
+The code Works under MS .net framwork 1.1 without problem, if i copy the
+Sytem.Data.dll from the original MS .net framework and replace it with the
+system.Data.dll of Mono, the code will work as designed.
+
+
+Config data
+
+Mono Version 1.11 (bugs also on 1.02)
+Operating System suse 8.0
+Database MySQL (using mono Shipped ByteFX adapter)
+
+
+Here comes a testcode:
+Steps to reproduce the problem:
+
+1 Create a table in a mysql DB with id field NOT NULL auto_increment
+====================[START Table structure]========================
+CREATE TABLE service (
+ id int(11) NOT NULL auto_increment,
+ comune varchar(255) NOT NULL default '',
+ attivita varchar(255) NOT NULL default '',
+ sottoattivita varchar(255) NOT NULL default '',
+ nome varchar(255) NOT NULL default '',
+ logid int(11) NOT NULL default '0',
+ statusid int(11) NOT NULL default '0',
+ package varchar(255) NOT NULL default '',
+ process varchar(255) NOT NULL default '',
+ PRIMARY KEY (id)
+) TYPE=MyISAM;
+====================[END Table structure]========================
+
+2. Compile this test program
+====================[START BugTest program]========================
+using System;
+using System.Data;
+using ByteFX.Data.MySqlClient;
+
+namespace Bug
+{
+ /// <summary>
+ /// Summary description for Class1.
+ /// </summary>
+ class Class1
+ {
+ /// <summary>
+ /// The main entry point for the application.
+ /// </summary>
+ [STAThread]
+ static void Main(string[] args)
+ {
+ MySqlConnection mySqlConnection = new
+MySqlConnection();
+ mySqlConnection.ConnectionString
+= "server=10.20.30.104;database=people10;userid=people_demo;password=people
+_demo";
+ mySqlConnection.Open();
+ string selectText = "SELECT * FROM service";
+ MySqlCommand theSelect = new MySqlCommand
+(selectText,mySqlConnection);
+ MySqlDataAdapter serviceAdapter = new
+MySqlDataAdapter(theSelect);
+ MySqlCommandBuilder cb = new MySqlCommandBuilder
+(serviceAdapter);
+ DataTable theTable = new DataTable();
+ serviceAdapter.Fill(theTable);
+
+ DataRow theRow = theTable.NewRow();
+ theRow["comune"]="test";
+ theRow["package"]="test";
+ theRow["attivita"]="test";
+ theRow["sottoattivita"]="test";
+ theRow["nome"]="test";
+ theRow["process"]="test";
+ theRow["logid"]=0;
+ theRow["statusid"]=0;
+ theTable.Rows.Add(theRow);
+
+ // the Primary Key "id" column is a auto-increment
+ serviceAdapter.Update(theTable);
+
+ Console.WriteLine("The key is "+theRow["id"]);
+ Console.ReadLine();
+ }
+ }
+}
+
+====================[END BugTest program]========================
+
+3. Compile it Like this.
+mcs Class1.cs /r:System.Data.dll,ByteFX.Data.dll
+
+
+Actual Results:
+iproxy:/tmp/Bug $ mono Class1.exe
+
+Unhandled Exception: System.Data.NoNullAllowedException: Column 'id' does
+not allow nulls.
+in <0x001bc> System.Data.UniqueConstraint:AssertConstraint
+(System.Data.DataRow)
+in <0x0012a> System.Data.DataRowCollection:ValidateDataRowInternal
+(System.Data.DataRow)
+in <0x00103> System.Data.DataRowCollection:Add (System.Data.DataRow)
+in <0x00229> Bug.Class1:Main (string[])
+
+
+Expected Results:
+iproxy:/tmp/Bug $ mono Class1.exe
+The key is 34
+
+iproxy:/tmp/Bug $ mono Class1.exe
+The key is 35
+
+
+How often does this happen?
+Alwais.. replacing the dll it works..
+
+Additional Information:
+Replacing System.Data.dll
+in
+/usr/local/lib/mono/gac/System.Data/1.0.5000.0__b77a5c561934e089/
+of
+
+drwxr-xr-x 2 root root 160 Oct 7 16:26 .
+drwxr-xr-x 3 root root 96 Oct 6 22:12 ..
+-rw-r--r-- 1 root root 1290240 Oct 7 16:26 System.Data.dll
+-rw-r--r-- 1 root root 509912 Oct 6 22:12 System.Data.dll.mdb
+-rwxr-xr-x 1 root root 513024 Oct 6 22:12 System.Data.dll.old
+
+Where old is the Mono one and
+the prog Works
+
+The workaroud id for US to be able to complete our dogfood work, i
+personaly discourage using MS stuff, and wait for the Data Adapter to work.
+
+Setting manualy the ID ot 0 ar a value will do the insert in the DB , but
+will not Refresh the ID value in the DataTable that will be the same value
+assinged and not reflecting the one in the actual DB
+
+also the Update method Updates the table in mysql but does'n refresh the
+DataTable object with the data contained in the db.
+
+Ceers.
+Alessandro.