Bug 316195 (MONO67757) - DataTable.Add does not work if a field is "NOT NULL" but set to auto_increment
Summary: DataTable.Add does not work if a field is "NOT NULL" but set to auto_increment
Status: RESOLVED FIXED
Alias: MONO67757
Product: Mono: Class Libraries
Classification: Mono
Component: Sys.Data (show other bugs)
Version: unspecified
Hardware: Other SuSE 8.0
: P3 - Medium : Major
Target Milestone: ---
Assignee: Forgotten User NWmiVNctto
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords: dogfood
Depends on:
Blocks:
 
Reported: 2004-10-07 16:24 UTC by Alessandro Faillace
Modified: 2007-09-15 21:24 UTC (History)
1 user (show)

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 18:55:44 UTC


---- Reported by afaillace@etnoteam.it 2004-10-07 09:24:47 MST ----

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.



---- Additional Comments From tsureshkumar@novell.com 2004-12-10 09:52:21 MST ----

fixed in svn.


Skipping unknown keyword: EPR.