Bug #16679 MySQLDataAdapter.FillSchema does not set default values
Submitted: 20 Jan 2006 17:44 Modified: 22 Feb 2006 8:53
Reporter: vincent ugenti Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:1.0.7 OS:Windows (Windows 2000 Professional)
Assigned to: CPU Architecture:Any

[20 Jan 2006 17:44] vincent ugenti
Description:
Using DataAdapter.FillSchema to add an empty DataTable to a DataSet that
contains the MySQL database schema.  All the columns and their types and whether
or not they allow nulls are set correctly, but the default values are not set
correctly.  As a result, when creating a new row, values are initialized to
DBNull instead of the correct default values.

This is the same bug that was reported for 1.0.4.  After reporting that bug, I noticed there was a newer version available so I downloaded and installed it.  The new version has the same problem.

How to repeat:
Create a table with default values for one or more columns.  Then in the
program, create an empty table with database schema programmatically:
*------------------*
DataSet dataSet = new DataSet();
MySqlDataAdapter dataAdapter = new MySqlDataAdapter("select * from <tablename>
limit 1", (MySqlConnection)DB.connection);
MySqlCommandBuilder commandBuilder = new MySqlCommandBuilder(dataAdapter);
dataAdapter.FillSchema(dataSet, System.Data.SchemaType.Source);
				commandBuilder.RefreshSchema();
*------------------*
dataSet.Tables["Table"].Columns will contain the collection of columns and will
know the correct column names and types from the call to FillSchema.  But the
DataColumn.DefaultValue property will not be set for any of the columns.  This
can be evidenced by calling dataSet.Tables["Table"].NewRow().  The resulting
DataRow object will have all fields initialized to DBNull instead of the default
values from the database schema.

Right now the only way to work around this is to hard-code the default values
into my program.  Obviously it would be better to retrieve the default values
from the schema in case they change later.

Suggested fix:
Update the MySqlDataAdapter.FillSchema method to populate the default values in
the resulting DataTable.Columns' DefaultValue properties.  Then the .NET
framework should be able to handle the rest.
[22 Feb 2006 8:53] Valeriy Kravchuk
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments
to the original bug instead.

Thank you for your interest in MySQL.

Additional info:

Duplicate of bug #16643.