Bug #15112 MySqlDateTime Constructor
Submitted: 21 Nov 2005 21:17 Modified: 29 Oct 2006 5:08
Reporter: C. Manson Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:1.0.7.30072 OS:Windows (Windows)
Assigned to: Reggie Burnett CPU Architecture:Any

[21 Nov 2005 21:17] C. Manson
Description:
There is "no constructors defined".

How to repeat:
private MySql.Data.Types.MySqlDateTime GetMySqlDateTime(DateTime datetime)
{
1 MySql.Data.Types.MySqlDateTime myDate;
2 myDate.Year = datetime.Year;
3 myDate.Month = datetime.Month;
4 myDate.Hour = datetime.Hour;
5 myDate.Minute = datetime.Minute;
6 myDate.Second = datetime.Second;
7 return myDate;
}

However, I'm getting the below error:
Use of unassigned local variable 'myDate' - line 2

If I change the function line 1 to:
MySql.Data.Types.MySqlDateTime myDate = new MySql.Data.Types.MySqlDateTime();
I then get this error:
The type 'MySql.Data.Types.MySqlDateTime' has no constructors defined

I'm running:
ADO.Net Driver for MySQL
MySql.Data.dll
runtime version: v2.0.50727
version: 1.0.7.30072 

Forum Link: 
http://forums.mysql.com/read.php?38,55558,55558#msg-55558
http://forums.mysql.com/read.php?38,54948,54948#msg-54948

Suggested fix:
the current 'fix' to convert in net 2 is with the "DateTime.Now.ToString("s").Replace("T", " ")
[26 Nov 2005 10:15] Valeriy Kravchuk
Thank you for the problem report. Sorry, but you put in into the wrong category (DBD::mysql is about Perl, not .Net), so I changed category to a more appropriate from my point of view. Please, confirm that you have this problem with MySQL Connector/Net version 1.0.7. 

Just to be sure that the report will be processed by those who really knowledgable in .Net.
[27 Dec 2005 0:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[27 Dec 2005 21:34] C. Manson
It's still an issue at last check.  No idea why it was auto-suspended.
[3 Jan 2006 9:52] Vasily Kishkin
Thanks for the bug report. I was able to reproduce the bug. My test case is attached.
[3 Jan 2006 9:52] Vasily Kishkin
Test case

Attachment: 15112.zip (application/force-download, text), 5.50 KiB.

[13 Mar 2006 15:30] stephan stricker
Are there any efforts to fix this bug. I wonder that this bug is categorized as "Non-critical" because it isn't possible to use the connector with VS2005 anymore when using date and time fields.

mfg

Stephan
[24 Apr 2006 23:22] Jason Taylor
This should absolutely be marked critical.   I cannot develop in VS2005 because of this error, nor can i use the 2.0 framework.  On top of all this the ado.net connector in VS2005 from what i can tell dosen't even provide VS a usable data provider, thus alienating all of the really good features from this package.
[25 Jul 2006 21:26] Chris Fairman
Please Change the severity to Critical or provide a work around.

-Chris
[5 Aug 2006 23:21] Emery Fabrice NZEYIMANA
In the definition of the MySqlDateTime Class, there are no public constructors. The defined constructors are internal. So, trying to solve this, I added a public contructor with no argument and this should set the MySqlDateTime value to "0001-01-01 00:00:00" which is the default value of DateTime value in C# 
Check the URL http://nzeyimana.nefa.rw/2006/08/06/mysqldatetime-constructor-problem/ for a possible solution I propose. 

Thanks 
Nzeyimana EF
[7 Aug 2006 22:03] Reggie Burnett
Everyone

This has been an open issue for some time and, in my mind, it's bigger than just adding a public ctor to MySqlDateTime.  There are several reasons I don't like that.

First, while MySQL allows zero date time values in some modes, we encourage people to run under strict mode and not allow zero datetime values.

Second, date time columns in MySQL can be null so I have a hard time understanding the justification for storing a zero date time value.

Third, MySqlDateTime would require significant work to make sure it "plays nice" in all the dataset scenarios.

I return a MySqlDateTime object when you specify "allow zero datetime" on  your connection string to allow you, the developer, to see if your column has a zero value.  I am now proposing an alternative.

Instead of returning MySqlDateTime, I can expose new methods on datareader that you can call that will let you know when the column has a zero value.  The problem with this is that it doens't really help when using datatables and datasets.  

Are there reasons why you have to use zero datetime values in your database?  Can you replace these values with NULL values and quit running with 'allow zero datetime'?
[10 Aug 2006 3:28] C. Manson
I really can't see working with MySQL with out a datetime class i can't instantiate. It's like not being able to instantiate a string or a structure.

Why not let app developers determine how they want to handle NULL and zero date time values?

Good to see some discuss on this issue though.
[10 Aug 2006 3:40] Reggie Burnett
Because MySqlDateTime is only needed when you have values that could be zero.  To my knowledge, no other db vendor allows date time values to be zero.  We shouldn't either but we do.  The RIGHT solution is not to allow zero date time values in your database.  in that case you would never need MySqlDateTime.  However, it appears that this is not always possible.
[28 Sep 2006 15:51] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/12738
[28 Sep 2006 15:57] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/12740
[28 Sep 2006 15:57] Reggie Burnett
Fixed in 1.0.8 and 5.0.1
[29 Oct 2006 5:08] MC Brown
A note has been added to the 1.0.8 changelog.