1 message in com.mysql.lists.dotnetConnector/NET commit: r119 - in branc...| From | Sent On | Attachments |
|---|---|---|
| rbur...@mysql.com | 10 Aug 2005 08:58 |
| Subject: | Connector/NET commit: r119 - in branches/1.0: . TestSuite mysqlclient mysqlclient/docs![]() |
|---|---|
| From: | rbur...@mysql.com (rbur...@mysql.com) |
| Date: | 08/10/2005 08:58:19 AM |
| List: | com.mysql.lists.dotnet |
Modified: branches/1.0/CHANGES branches/1.0/TestSuite/DateTimeTests.cs branches/1.0/mysqlclient/ConnectionString.cs branches/1.0/mysqlclient/datareader.cs branches/1.0/mysqlclient/docs/MySqlConnection.xml Log: Implemented Convert Zero DateTime connection option. WL# 2436
Modified: branches/1.0/CHANGES
===================================================================
--- branches/1.0/CHANGES 2005-08-10 15:31:42 UTC (rev 118)
+++ branches/1.0/CHANGES 2005-08-10 15:58:41 UTC (rev 119)
@@ -44,6 +44,7 @@
Fixed bug where adding parameter objects that had been independently
constructed did not work right.
Changed internal class MySqlSingle to MySqlFloat
Implemented new BIT data type
+ Implemented Convert Zero DateTime connection option.
1-20-05 - Version 1.0.4
Modified: branches/1.0/TestSuite/DateTimeTests.cs =================================================================== --- branches/1.0/TestSuite/DateTimeTests.cs 2005-08-10 15:31:42 UTC (rev 118) +++ branches/1.0/TestSuite/DateTimeTests.cs 2005-08-10 15:58:41 UTC (rev 119) @@ -48,6 +48,39 @@ }
[Test()]
+ public void ConvertZeroDateTime()
+ {
+ execSQL("INSERT INTO Test VALUES(1, '0000-00-00', '0000-00-00', '00:00:00',
NULL)");
+
+ MySqlConnection c;
+ MySqlDataReader reader = null;
+
+ string connStr = this.GetConnectionString(true);
+ connStr += ";convert zero datetime=yes";
+ c = new MySqlConnection(connStr);
+
+ try
+ {
+ c.Open();
+
+ MySqlCommand cmd = new MySqlCommand("SELECT * FROM test", c);
+ reader = cmd.ExecuteReader();
+ Assert.IsTrue(reader.Read());
+ Assert.AreEqual(DateTime.MinValue.Date, reader.GetDateTime(1).Date);
+ Assert.AreEqual(DateTime.MinValue.Date, reader.GetDateTime(2).Date);
+ }
+ catch (Exception ex)
+ {
+ Assert.Fail(ex.Message);
+ }
+ finally
+ {
+ if (reader != null) reader.Close();
+ c.Close();
+ }
+ }
+
+ [Test()]
public void TestNotAllowZerDateAndTime()
{
execSQL("INSERT INTO Test VALUES(1, 'Test', '0000-00-00', '0000-00-00',
'00:00:00')");
Modified: branches/1.0/mysqlclient/ConnectionString.cs
===================================================================
--- branches/1.0/mysqlclient/ConnectionString.cs 2005-08-10 15:31:42 UTC (rev
118)
+++ branches/1.0/mysqlclient/ConnectionString.cs 2005-08-10 15:58:41 UTC (rev
119)
@@ -241,6 +241,15 @@
}
[Category("Other")]
+ [Description("Should illegal datetime values be converted to
DateTime.MinValue")]
+ [DefaultValue(false)]
+ public bool ConvertZeroDateTime
+ {
+ get { return GetBool("convertzerodatetime"); }
+ set { keyValues["convertzerodatetime"] = value; }
+ }
+
+ [Category("Other")]
[Description("Character set this connection should use")]
[DefaultValue(null)]
public string CharacterSet
@@ -332,12 +341,15 @@
defaults["pipeName"] = "MySQL";
defaults["memname"] = "MYSQL";
defaults["allowzerodatetime"] = false;
+ defaults["convertzerodatetime"] = false;
}
return (Hashtable)defaults.Clone();
}
protected override bool ConnectionParameterParsed(Hashtable hash, string key,
string value)
{
+ bool boolVal = value.ToLower() == "yes" || value.ToLower() == "true";
+
switch (key.ToLower())
{
case "character set":
@@ -347,8 +359,7 @@
case "use compression": case "compress": - hash["compress"] = - value.ToLower() == "yes" || value.ToLower() == "true"; + hash["compress"] = boolVal; return true;
case "protocol": @@ -368,11 +379,11 @@ return true;
case "allow batch":
- hash["allow batch"] = value.ToLower() == "yes" || value.ToLower() ==
"true";
+ hash["allow batch"] = boolVal;
return true;
case "logging": - hash["logging"] = value.ToLower() == "yes" || value.ToLower() == "true"; + hash["logging"] = boolVal; return true;
case "shared memory name": @@ -381,12 +392,17 @@
case "old syntax": case "oldsyntax": - hash["oldsyntax"] = value.ToLower() == "yes" || value.ToLower() == "true"; + hash["oldsyntax"] = boolVal; return true;
+ case "convert zero datetime":
+ case "convertzerodatetime":
+ hash["convertzerodatetime"] = boolVal;
+ return true;
+
case "allow zero datetime":
case "allowzerodatetime":
- hash["allowzerodatetime"] = value.ToLower() == "yes" || value.ToLower() ==
"true";
+ hash["allowzerodatetime"] = boolVal;
return true;
}
Modified: branches/1.0/mysqlclient/datareader.cs =================================================================== --- branches/1.0/mysqlclient/datareader.cs 2005-08-10 15:31:42 UTC (rev 118) +++ branches/1.0/mysqlclient/datareader.cs 2005-08-10 15:58:41 UTC (rev 119) @@ -312,9 +312,15 @@ { MySqlValue val = GetFieldValue(index); if (val is MySqlDateTime) - return (val as MySqlDateTime).GetDateTime(); - if (val is MySqlString) { + MySqlDateTime dt = (MySqlDateTime)val; + if (connection.Settings.ConvertZeroDateTime && !dt.IsValidDateTime) + return DateTime.MinValue; + else + return dt.GetDateTime(); + } + else if (val is MySqlString) + { MySqlDateTime d = new MySqlDateTime( MySqlDbType.Datetime ); d = d.ParseMySql( (val as MySqlString).Value, true ); return d.GetDateTime(); @@ -541,10 +547,13 @@ // so .ToString() will print '0000-00-00' correctly if (val is MySqlDateTime) { - if (connection.Settings.AllowZeroDateTime) + MySqlDateTime dt = (MySqlDateTime)val; + if (! dt.IsValidDateTime && connection.Settings.ConvertZeroDateTime) + return DateTime.MinValue; + else if (connection.Settings.AllowZeroDateTime) return val; else - return (val as MySqlDateTime).GetDateTime(); + return dt.GetDateTime(); }
return val.ValueAsObject;
Modified: branches/1.0/mysqlclient/docs/MySqlConnection.xml
===================================================================
--- branches/1.0/mysqlclient/docs/MySqlConnection.xml 2005-08-10 15:31:42 UTC
(rev 118)
+++ branches/1.0/mysqlclient/docs/MySqlConnection.xml 2005-08-10 15:58:41 UTC
(rev 119)
@@ -818,6 +818,12 @@
False will cause a DateTime object to be returned for legal values and an
exception will be thrown for illegal values.</td>
</tr>
<tr>
+ <td>Convert Zero Datetime</td>
+ <td>false</td>
+ <td>True to have MySqlDataReader.GetValue() and
MySqlDataReader.GetDateTime()
+ return DateTime.MinValue for date or datetime columns that have illegal
values.</td>
+ </tr>
+ <tr>
<td>Old Syntax<para> -or- </para>OldSyntax</td>
<td>false</td>
<td>




