Modified:
branches/1.0/CHANGES
branches/1.0/TestSuite/DateTimeTests.cs
branches/1.0/mysqlclient/CommandResult.cs
branches/1.0/mysqlclient/Driver.cs
branches/1.0/mysqlclient/datareader.cs
Log:
Bug #19481 Where clause with datetime throws exception [any warning causes the exception]
The problem here is that the driver must issue a sql query to the server to retrieve the warnings and this uses a data reader. Only one reader can be open at one time so if you had a query that might return more than one resultset, then at
the end of the first it tried to retrieve the warnings. This failed since there is already a reader open. The solution
was to wait until the reader is closed to report the warnings. This is suboptimal since the warning callbacks will not occur until you close but it is the only easy way to solve it. The other way would be to retrieve the warnings without
using a data reader but that would be alot more effort.
Modified: branches/1.0/CHANGES
===================================================================
--- branches/1.0/CHANGES 2006-05-18 19:08:04 UTC (rev 235)
+++ branches/1.0/CHANGES 2006-05-18 19:53:53 UTC (rev 236)
@@ -5,7 +5,8 @@
Bug #16645 FOUND_ROWS() Bug [can't repeat - added test case]
Bug #18570 Unsigned tinyint (NET byte) incorrectly determined param type from param val [fixed]
Bug #19261 Supplying Input Parameters [fixed]
-
+ Bug #19481 Where clause with datetime throws exception [any warning causes the exception] [fixed]
+
x-xx-05 - Version 1.0.7
Bugs fixed or addressed
Modified: branches/1.0/TestSuite/DateTimeTests.cs
===================================================================
--- branches/1.0/TestSuite/DateTimeTests.cs 2006-05-18 19:08:04 UTC (rev 235)
+++ branches/1.0/TestSuite/DateTimeTests.cs 2006-05-18 19:53:53 UTC (rev 236)
@@ -1,21 +1,21 @@
-// Copyright (C) 2004-2005 MySQL AB
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License version 2 as published by
-// the Free Software Foundation
-//
-// There are special exceptions to the terms and conditions of the GPL
-// as it is applied to this software. View the full text of the
-// exception in file EXCEPTIONS in the directory of this software
-// distribution.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
+// Copyright (C) 2004-2006 MySQL AB
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as published by
+// the Free Software Foundation
+//
+// There are special exceptions to the terms and conditions of the GPL
+// as it is applied to this software. View the full text of the
+// exception in file EXCEPTIONS in the directory of this software
+// distribution.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System;
@@ -26,6 +26,7 @@
using MySql.Data.Types;
using System.Globalization;
using NUnit.Framework;
+using System.Text;
namespace MySql.Data.MySqlClient.Tests
{
@@ -148,88 +149,88 @@
}
}
- [Test]
- public void TestAllowZeroDateTime()
- {
- execSQL("INSERT INTO Test (id, d, dt) VALUES (1, '0000-00-00', '0000-00-00 00:00:00')");
-
- MySqlConnection c = new MySqlConnection(
- conn.ConnectionString + ";pooling=false;AllowZeroDatetime=true" );
- c.Open();
- MySqlDataReader reader = null;
- try
- {
- MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", c);
- reader = cmd.ExecuteReader();
- reader.Read();
-
- Assert.IsTrue( reader.GetValue(1) is MySqlDateTime );
- Assert.IsTrue( reader.GetValue(2) is MySqlDateTime );
-
- Assert.IsFalse( reader.GetMySqlDateTime(1).IsValidDateTime );
- Assert.IsFalse( reader.GetMySqlDateTime(2).IsValidDateTime );
-
+ [Test]
+ public void TestAllowZeroDateTime()
+ {
+ execSQL("INSERT INTO Test (id, d, dt) VALUES (1, '0000-00-00', '0000-00-00 00:00:00')");
+
+ MySqlConnection c = new MySqlConnection(
+ conn.ConnectionString + ";pooling=false;AllowZeroDatetime=true" );
+ c.Open();
+ MySqlDataReader reader = null;
+ try
+ {
+ MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", c);
+ reader = cmd.ExecuteReader();
+ reader.Read();
+
+ Assert.IsTrue( reader.GetValue(1) is MySqlDateTime );
+ Assert.IsTrue( reader.GetValue(2) is MySqlDateTime );
+
+ Assert.IsFalse( reader.GetMySqlDateTime(1).IsValidDateTime );
+ Assert.IsFalse( reader.GetMySqlDateTime(2).IsValidDateTime );
+
try
- {
- reader.GetDateTime(1);
- Assert.Fail("This should not succeed");
- }
- catch (MySqlConversionException) {}
-
-
- }
- catch (MySqlException ex)
- {
- Assert.Fail( ex.Message );
- }
- finally
- {
- if (reader != null) reader.Close();
- c.Close();
- }
- }
-
- [Test]
- public void InsertDateTimeValue()
- {
- MySqlConnection c = new MySqlConnection( conn.ConnectionString + ";allow zero datetime=yes");
+ {
+ reader.GetDateTime(1);
+ Assert.Fail("This should not succeed");
+ }
+ catch (MySqlConversionException) {}
+
+
+ }
+ catch (MySqlException ex)
+ {
+ Assert.Fail( ex.Message );
+ }
+ finally
+ {
+ if (reader != null) reader.Close();
+ c.Close();
+ }
+ }
+
+ [Test]
+ public void InsertDateTimeValue()
+ {
+ MySqlConnection c = new MySqlConnection( conn.ConnectionString + ";allow zero datetime=yes");
try
- {
- c.Open();
- MySqlDataAdapter da = new MySqlDataAdapter("SELECT id, dt FROM Test", c);
- MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
+ {
+ c.Open();
+ MySqlDataAdapter da = new MySqlDataAdapter("SELECT id, dt FROM Test", c);
+ MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
cb.ToString(); // keep the compiler happy
-
- DataTable dt = new DataTable();
- dt.Columns.Add(new DataColumn("id", typeof(int)));
- dt.Columns.Add(new DataColumn("dt", typeof(DateTime)));
-
- da.Fill(dt);
-
- DateTime now = DateTime.Now;
- DataRow row = dt.NewRow();
- row["id"] = 1;
- row["dt"] = now;
- dt.Rows.Add(row);
- da.Update(dt);
-
- dt.Clear();
- da.Fill(dt);
-
- Assert.AreEqual(1, dt.Rows.Count);
- Assert.AreEqual(now.Date, ((DateTime)dt.Rows[0]["dt"]).Date );
- }
+
+ DataTable dt = new DataTable();
+ dt.Columns.Add(new DataColumn("id", typeof(int)));
+ dt.Columns.Add(new DataColumn("dt", typeof(DateTime)));
+
+ da.Fill(dt);
+
+ DateTime now = DateTime.Now;
+ DataRow row = dt.NewRow();
+ row["id"] = 1;
+ row["dt"] = now;
+ dt.Rows.Add(row);
+ da.Update(dt);
+
+ dt.Clear();
+ da.Fill(dt);
+
+ Assert.AreEqual(1, dt.Rows.Count);
+ Assert.AreEqual(now.Date, ((DateTime)dt.Rows[0]["dt"]).Date );
+ }
catch (Exception ex)
- {
- Assert.Fail( ex.Message );
- }
+ {
+ Assert.Fail( ex.Message );
+ }
finally
- {
- c.Close();
- }
- }
-
+ {
+ c.Close();
+ }
+ }
+
[Test]
public void SortingMySqlDateTimes()
{
@@ -263,33 +264,33 @@
}
}
- [Test()]
- public void TestZeroDateTimeException()
- {
- execSQL("INSERT INTO Test (id, d, dt) VALUES (1, '0000-00-00', '0000-00-00 00:00:00')");
-
- MySqlDataReader reader = null;
- try
- {
- MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", conn);
- reader = cmd.ExecuteReader();
- reader.Read();
- reader.GetDateTime(2);
- Assert.Fail("Should throw an exception");
- }
- catch (MySqlConversionException)
- {
- }
- catch (MySqlException ex)
- {
- Assert.Fail( ex.Message );
- }
- finally
- {
- if (reader != null) reader.Close();
- }
- }
-
+ [Test()]
+ public void TestZeroDateTimeException()
+ {
+ execSQL("INSERT INTO Test (id, d, dt) VALUES (1, '0000-00-00', '0000-00-00 00:00:00')");
+
+ MySqlDataReader reader = null;
+ try
+ {
+ MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", conn);
+ reader = cmd.ExecuteReader();
+ reader.Read();
+ reader.GetDateTime(2);
+ Assert.Fail("Should throw an exception");
+ }
+ catch (MySqlConversionException)
+ {
+ }
+ catch (MySqlException ex)
+ {
+ Assert.Fail( ex.Message );
+ }
+ finally
+ {
+ if (reader != null) reader.Close();
+ }
+ }
+
/// <summary>
/// Bug #8929 Timestamp values with a date > 10/29/9997 cause problems
/// </summary>
@@ -337,6 +338,44 @@
Assert.AreEqual(4, date.Day);
}
+ /// <summary>
+ /// Bug #19481 Where clause with datetime throws exception [any warning causes the exception]
+ /// </summary>
+ [Test]
+ public void Bug19481()
+ {
+ execSQL("DROP TABLE IF EXISTS test");
+ execSQL("CREATE TABLE test(ID INT NOT NULL AUTO_INCREMENT, " +
+ "SATELLITEID VARCHAR(3) NOT NULL, ANTENNAID INT, AOS_TIMESTAMP DATETIME NOT NULL, " +
+ "TEL_TIMESTAMP DATETIME, LOS_TIMESTAMP DATETIME, PRIMARY KEY (ID))");
+ execSQL("INSERT INTO test VALUES (NULL,'224','0','2005-07-24 00:00:00'," +
+ "'2005-07-24 00:02:00','2005-07-24 00:22:00')");
+ execSQL("INSERT INTO test VALUES (NULL,'155','24','2005-07-24 03:00:00'," +
+ "'2005-07-24 03:02:30','2005-07-24 03:20:00')");
+ execSQL("INSERT INTO test VALUES (NULL,'094','34','2005-07-24 09:00:00'," +
+ "'2005-07-24 09:00:30','2005-07-24 09:15:00')");
+ execSQL("INSERT INTO test VALUES (NULL,'224','54','2005-07-24 12:00:00'," +
+ "'2005-07-24 12:01:00','2005-07-24 12:33:00')");
+ execSQL("INSERT INTO test VALUES (NULL,'155','25','2005-07-24 15:00:00'," +
+ "'2005-07-24 15:02:00','2005-07-24 15:22:00')");
+ execSQL("INSERT INTO test VALUES (NULL,'094','0','2005-07-24 17:00:00'," +
+ "'2005-07-24 17:02:12','2005-07-24 17:20:00')");
+ execSQL("INSERT INTO test VALUES (NULL,'224','24','2005-07-24 19:00:00'," +
+ "'2005-07-24 19:02:00','2005-07-24 19:27:00')");
+ execSQL("INSERT INTO test VALUES (NULL,'155','34','2005-07-24 21:00:00'," +
+ "'2005-07-24 21:02:33','2005-07-24 21:22:55')");
+ execSQL("INSERT INTO test VALUES (NULL,'094','55','2005-07-24 23:00:00'," +
+ "'2005-07-24 23:00:45','2005-07-24 23:22:23')");
+
+ DateTime date = DateTime.Parse("7/24/2005");
+ StringBuilder sql = new StringBuilder();
+ sql.AppendFormat("SELECT ID, ANTENNAID, TEL_TIMESTAMP, LOS_TIMESTAMP FROM test " +
+ "WHERE TEL_TIMESTAMP >= '{0}'", date.ToString("u"));
+ MySqlDataAdapter da = new MySqlDataAdapter(sql.ToString(), conn);
+ DataSet dataSet = new DataSet();
+ da.Fill(dataSet);
+ }
+
}
}
Modified: branches/1.0/mysqlclient/CommandResult.cs
===================================================================
--- branches/1.0/mysqlclient/CommandResult.cs 2006-05-18 19:08:04 UTC (rev 235)
+++ branches/1.0/mysqlclient/CommandResult.cs 2006-05-18 19:53:53 UTC (rev 236)
@@ -1,231 +1,227 @@
-// Copyright (C) 2004-2005 MySQL AB
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License version 2 as published by
-// the Free Software Foundation
-//
-// There are special exceptions to the terms and conditions of the GPL
-// as it is applied to this software. View the full text of the
-// exception in file EXCEPTIONS in the directory of this software
-// distribution.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-using System;
-using System.Collections;
-using MySql.Data.Types;
-
-namespace MySql.Data.MySqlClient
-{
- /// <summary>
- /// Summary description for CommandResult.
- /// </summary>
- internal class CommandResult
- {
- private Driver driver;
-
- private long affectedRows;
- private ulong fieldCount;
- private long lastInsertId;
-
- private bool readSchema;
- private bool readRows;
- private bool isBinary;
- private MySqlField[] fields;
- private MySqlValue[] values;
- private bool dataRowOpen;
- private bool usingSequentialAccess;
- private int seqColumn;
-
- public CommandResult( Driver d, bool isBinary )
- {
- driver = d;
- this.isBinary = isBinary;
- affectedRows = -1;
- ReadNextResult(true);
- }
-
-/* public CommandResult( Driver d )
- {
- driver = d;
- }
-*/
- #region Properties
-
+// Copyright (C) 2004-2006 MySQL AB
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as published by
+// the Free Software Foundation
+//
+// There are special exceptions to the terms and conditions of the GPL
+// as it is applied to this software. View the full text of the
+// exception in file EXCEPTIONS in the directory of this software
+// distribution.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+using System;
+using System.Collections;
+using MySql.Data.Types;
+
+namespace MySql.Data.MySqlClient
+{
+ /// <summary>
+ /// Summary description for CommandResult.
+ /// </summary>
+ internal class CommandResult
+ {
+ private Driver driver;
+
+ private long affectedRows;
+ private ulong fieldCount;
+ private long lastInsertId;
+
+ private bool readSchema;
+ private bool readRows;
+ private bool isBinary;
+ private MySqlField[] fields;
+ private MySqlValue[] values;
+ private bool dataRowOpen;
+ private bool usingSequentialAccess;
+ private int seqColumn;
+
+ public CommandResult( Driver d, bool isBinary )
+ {
+ driver = d;
+ this.isBinary = isBinary;
+ affectedRows = -1;
+ ReadNextResult(true);
+ }
+
+/* public CommandResult( Driver d )
+ {
+ driver = d;
+ }
+*/
+ #region Properties
+
public MySqlValue this[int index]
- {
- get { return values[index]; }
- set { values[index] = value; }
- }
-
- public MySqlField[] Fields
- {
- get { return fields; }
- }
-
- public bool IsResultSet
- {
- get { return fieldCount > 0; }
- }
-
-/* public long LastInsertId
- {
- get { return lastInsertId; }
- set { lastInsertId = value; }
- }
-*/
- //TODO: remove comment
-/* public ulong FieldCount
- {
-// get { return fieldCount; }
-// set { fieldCount = value; }
- }
-*/
- public long AffectedRows
- {
- get { return affectedRows; }
-// set { affectedRows = value; }
- }
-
- #endregion
-
- public MySqlValue ReadColumnValue(int index)
- {
- if (! usingSequentialAccess || seqColumn == index)
- return this[index];
-
- if (index < seqColumn)
- throw new MySqlException("Invalid attempt to read a prior column using SequentialAccess");
-
- while ( (seqColumn+1) < index )
- {
- driver.SkipField(values[seqColumn+1]);
- seqColumn++;
- }
-
- values[index] = driver.ReadFieldValue( index, fields[index], values[index] );
- seqColumn = index;
- return values[index];
- }
-
+ {
+ get { return values[index]; }
+ set { values[index] = value; }
+ }
+
+ public MySqlField[] Fields
+ {
+ get { return fields; }
+ }
+
+ public bool IsResultSet
+ {
+ get { return fieldCount > 0; }
+ }
+
+/* public long LastInsertId
+ {
+ get { return lastInsertId; }
+ set { lastInsertId = value; }
+ }
+*/
+ //TODO: remove comment
+/* public ulong FieldCount
+ {
+// get { return fieldCount; }
+// set { fieldCount = value; }
+ }
+*/
+ public long AffectedRows
+ {
+ get { return affectedRows; }
+// set { affectedRows = value; }
+ }
+
+ #endregion
+
+ public MySqlValue ReadColumnValue(int index)
+ {
+ if (! usingSequentialAccess || seqColumn == index)
+ return this[index];
+
+ if (index < seqColumn)
+ throw new MySqlException("Invalid attempt to read a prior column using SequentialAccess");
+
+ while ( (seqColumn+1) < index )
+ {
+ driver.SkipField(values[seqColumn+1]);
+ seqColumn++;
+ }
+
+ values[index] = driver.ReadFieldValue( index, fields[index], values[index] );
+ seqColumn = index;
+ return values[index];
+ }
+
public bool ReadNextResult(bool isFirst)
- {
- long rows = 0;
-
- while ( (driver.ServerStatus & (ServerStatusFlags.MoreResults | ServerStatusFlags.AnotherQuery )) != 0 ||
- isFirst)
- {
- fieldCount = (ulong)driver.ReadResult( ref rows, ref lastInsertId );
- if (rows != -1)
- {
- if (affectedRows == -1) affectedRows = 0;
- affectedRows += rows;
- }
- if (isFirst) isFirst = false;
-
+ {
+ long rows = 0;
+
+ while ( (driver.ServerStatus & (ServerStatusFlags.MoreResults | ServerStatusFlags.AnotherQuery )) != 0 ||
+ isFirst)
+ {
+ fieldCount = (ulong)driver.ReadResult( ref rows, ref lastInsertId );
+ if (rows != -1)
+ {
+ if (affectedRows == -1) affectedRows = 0;
+ affectedRows += rows;
+ }
+ if (isFirst) isFirst = false;
+
if (IsResultSet)
- {
- readSchema = false;
- readRows = false;
- return true;
- }
- }
-
- // if our batch resulted in warnings, then report them now
- if (driver.HasWarnings)
- driver.ReportWarnings();
-
- return false;
- }
-
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- public bool Load()
- {
+ {
+ readSchema = false;
+ readRows = false;
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <returns></returns>
+ public bool Load()
+ {
try
- {
- driver.ReadFieldMetadata( (int)fieldCount, ref fields );
- readSchema = true;
-
- values = new MySqlValue[ fields.Length ];
+ {
+ driver.ReadFieldMetadata( (int)fieldCount, ref fields );
+ readSchema = true;
+
+ values = new MySqlValue[ fields.Length ];
for (int i=0; i < fields.Length; i++)
- values[i] = fields[i].GetValueObject();
-
+ values[i] = fields[i].GetValueObject();
+
if (! driver.OpenDataRow(fields.Length, isBinary))
- {
- readRows = true;
- return false;
- }
- dataRowOpen = true;
-
- return true;
- }
+ {
+ readRows = true;
+ return false;
+ }
+ dataRowOpen = true;
+
+ return true;
+ }
catch (Exception)
- {
- readSchema = true;
- readRows = true;
- throw;
- }
- }
-
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- public bool ReadDataRow(bool loadFields)
- {
- if ( readRows ) return false;
-
- seqColumn = -1;
+ {
+ readSchema = true;
+ readRows = true;
+ throw;
+ }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <returns></returns>
+ public bool ReadDataRow(bool loadFields)
+ {
+ if ( readRows ) return false;
+
+ seqColumn = -1;
if (! dataRowOpen)
- {
+ {
if (! driver.OpenDataRow(fields.Length, isBinary) )
- {
- readRows = true;
- return false;
- }
- }
- dataRowOpen = false;
- usingSequentialAccess = ! loadFields;
-
+ {
+ readRows = true;
+ return false;
+ }
+ }
+ dataRowOpen = false;
+ usingSequentialAccess = ! loadFields;
+
if (! loadFields)
- return true;
-
+ return true;
+
for (int x=0; x < fields.Length; x++)
values[x] = driver.ReadFieldValue( x, fields[x], values[x] );
-
- return true;
- }
-
-
- /// <summary>
- ///
- /// </summary>
- public void Consume()
- {
- // if we are not a resultset, then we are done
- if (! IsResultSet) return;
-
- if (! readSchema)
- {
- driver.ReadFieldMetadata( (int)fieldCount, ref fields );
- readSchema = true;
- }
-
+
+ return true;
+ }
+
+
+ /// <summary>
+ ///
+ /// </summary>
+ public void Consume()
+ {
+ // if we are not a resultset, then we are done
+ if (! IsResultSet) return;
+
+ if (! readSchema)
+ {
+ driver.ReadFieldMetadata( (int)fieldCount, ref fields );
+ readSchema = true;
+ }
+
if (! readRows)
- {
- while (driver.OpenDataRow( 0, false )) {}
- readRows = true;
- }
- }
- }
-}
+ {
+ while (driver.OpenDataRow( 0, false )) {}
+ readRows = true;
+ }
+ }
+ }
+}
Modified: branches/1.0/mysqlclient/Driver.cs
===================================================================
--- branches/1.0/mysqlclient/Driver.cs 2006-05-18 19:08:04 UTC (rev 235)
+++ branches/1.0/mysqlclient/Driver.cs 2006-05-18 19:53:53 UTC (rev 236)
@@ -1,23 +1,23 @@
-// Copyright (C) 2004-2005 MySQL AB
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License version 2 as published by
-// the Free Software Foundation
-//
-// There are special exceptions to the terms and conditions of the GPL
-// as it is applied to this software. View the full text of the
-// exception in file EXCEPTIONS in the directory of this software
-// distribution.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
+// Copyright (C) 2004-2006 MySQL AB
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as published by
+// the Free Software Foundation
+//
+// There are special exceptions to the terms and conditions of the GPL
+// as it is applied to this software. View the full text of the
+// exception in file EXCEPTIONS in the directory of this software
+// distribution.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
using System;
using System.Text;
using System.Collections;
@@ -33,24 +33,24 @@
{
protected int threadId;
protected DBVersion version;
- protected Encoding encoding;
- protected ServerStatusFlags serverStatus;
- protected MySqlConnectionString connectionString;
- protected ClientFlags serverCaps;
- protected bool isOpen;
- protected DateTime creationTime;
- protected int serverLanguage;
- protected Hashtable serverProps;
- protected MySqlConnection connection;
- protected Hashtable charSets;
- protected bool hasWarnings;
- protected long maxPacketSize;
+ protected Encoding encoding;
+ protected ServerStatusFlags serverStatus;
+ protected MySqlConnectionString connectionString;
+ protected ClientFlags serverCaps;
+ protected bool isOpen;
+ protected DateTime creationTime;
+ protected int serverLanguage;
+ protected Hashtable serverProps;
+ protected MySqlConnection connection;
+ protected Hashtable charSets;
+ protected bool hasWarnings;
+ protected long maxPacketSize;
public Driver(MySqlConnectionString settings)
{
- encoding = System.Text.Encoding.GetEncoding("latin1");
- connectionString = settings;
- threadId = -1;
+ encoding = System.Text.Encoding.GetEncoding("latin1");
+ connectionString = settings;
+ threadId = -1;
}
#region Properties
@@ -70,28 +70,28 @@
get { return version; }
}
- public MySqlConnectionString Settings
- {
- get { return connectionString; }
- set { connectionString = value; }
- }
-
- public Encoding Encoding
- {
- get { return encoding; }
- set { encoding = value; }
- }
-
+ public MySqlConnectionString Settings
+ {
+ get { return connectionString; }
+ set { connectionString = value; }
+ }
+
+ public Encoding Encoding
+ {
+ get { return encoding; }
+ set { encoding = value; }
+ }
+
public ServerStatusFlags ServerStatus
- {
- get { return serverStatus; }
- }
-
+ {
+ get { return serverStatus; }
+ }
+
public bool HasWarnings
- {
- get { return hasWarnings; }
- }
-
+ {
+ get { return hasWarnings; }
+ }
+
#endregion
public string Property(string key)
@@ -99,37 +99,37 @@
return (string)serverProps[key];
}
- public bool IsTooOld()
- {
- TimeSpan ts = DateTime.Now.Subtract( creationTime );
- if (ts.Seconds > Settings.ConnectionLifetime)
- return true;
- return false;
- }
+ public bool IsTooOld()
+ {
+ TimeSpan ts = DateTime.Now.Subtract( creationTime );
+ if (ts.Seconds > Settings.ConnectionLifetime)
+ return true;
+ return false;
+ }
public static Driver Create( MySqlConnectionString settings )
- {
- Driver d;
-// if (settings.Protocol == ConnectionProtocol.Client)
-// d = new ClientDriver( settings );
-// else
- d = new NativeDriver( settings );
- d.Open();
- return d;
- }
+ {
+ Driver d;
+// if (settings.Protocol == ConnectionProtocol.Client)
+// d = new ClientDriver( settings );
+// else
+ d = new NativeDriver( settings );
+ d.Open();
+ return d;
+ }
public virtual void Open()
{
- creationTime = DateTime.Now;
+ creationTime = DateTime.Now;
}
public virtual void SafeClose()
{
try
- {
- Close();
- }
- catch (Exception) { }
+ {
+ Close();
+ }
+ catch (Exception) { }
}
public virtual void Close()
@@ -137,84 +137,84 @@
isOpen = false;
}
- /// <summary>
- /// I don't like this setup but can't think of a better way of doing
- /// right now.
- /// </summary>
- /// <param name="connection"></param>
- public virtual void Configure(MySqlConnection connection)
- {
- this.connection = connection;
-
- // if we have already configured this driver and we are supposed
- // to cache server config, then exit
- if (serverProps != null && connectionString.CacheServerConfig)
- return;
-
- // load server properties
- serverProps = new Hashtable();
- MySqlCommand cmd = new MySqlCommand("SHOW VARIABLES", connection);
-
- try
- {
- MySqlDataReader reader = cmd.ExecuteReader();
- while (reader.Read())
- serverProps[reader.GetValue(0)] = reader.GetString(1);
- reader.Close();
- }
- catch (Exception ex)
- {
- Logger.LogException( ex );
- throw;
- }
-
- if (serverProps.Contains( "max_allowed_packet"))
- maxPacketSize = Convert.ToInt64(serverProps["max_allowed_packet"]);
-
-#if AUTHENTICATED
- string licenseType = (string)serverProps["license"];
- if (licenseType == null || licenseType.Length == 0 ||
- licenseType != "commercial")
- throw new MySqlException( "This client library licensed only for use with commercially-licensed MySQL servers." );
-#endif
- LoadCharacterSets();
-
- string charSet = connectionString.CharacterSet;
+ /// <summary>
+ /// I don't like this setup but can't think of a better way of doing
+ /// right now.
+ /// </summary>
+ /// <param name="connection"></param>
+ public virtual void Configure(MySqlConnection connection)
+ {
+ this.connection = connection;
+
+ // if we have already configured this driver and we are supposed
+ // to cache server config, then exit
+ if (serverProps != null && connectionString.CacheServerConfig)
+ return;
+
+ // load server properties
+ serverProps = new Hashtable();
+ MySqlCommand cmd = new MySqlCommand("SHOW VARIABLES", connection);
+
+ try
+ {
+ MySqlDataReader reader = cmd.ExecuteReader();
+ while (reader.Read())
+ serverProps[reader.GetValue(0)] = reader.GetString(1);
+ reader.Close();
+ }
+ catch (Exception ex)
+ {
+ Logger.LogException( ex );
+ throw;
+ }
+
+ if (serverProps.Contains( "max_allowed_packet"))
+ maxPacketSize = Convert.ToInt64(serverProps["max_allowed_packet"]);
+
+#if AUTHENTICATED
+ string licenseType = (string)serverProps["license"];
+ if (licenseType == null || licenseType.Length == 0 ||
+ licenseType != "commercial")
+ throw new MySqlException( "This client library licensed only for use with commercially-licensed MySQL servers." );
+#endif
+ LoadCharacterSets();
+
+ string charSet = connectionString.CharacterSet;
if (charSet == null || charSet.Length == 0)
- {
- if (! version.isAtLeast(4,1,0))
- {
- if (serverProps.Contains( "character_set" ))
- charSet = serverProps["character_set"].ToString();
- }
- else
- {
- charSet = (string)charSets[ serverLanguage ];
-
- }
- }
-
- // now tell the server which character set we will send queries in and which charset we
- // want results in
+ {
+ if (! version.isAtLeast(4,1,0))
+ {
+ if (serverProps.Contains( "character_set" ))
+ charSet = serverProps["character_set"].ToString();
+ }
+ else
+ {
+ charSet = (string)charSets[ serverLanguage ];
+
+ }
+ }
+
+ // now tell the server which character set we will send queries in and which charset we
+ // want results in
if (version.isAtLeast(4,1,0))
- {
- cmd.CommandText = "SET character_set_results=NULL";
- object clientCharSet = serverProps["character_set_client"];
- object connCharSet = serverProps["character_set_connection"];
- if ((clientCharSet != null && clientCharSet.ToString() != charSet) ||
- (connCharSet != null && connCharSet.ToString() != charSet))
- {
- cmd.CommandText = "SET NAMES " + charSet + ";" + cmd.CommandText;
- }
- cmd.ExecuteNonQuery();
- }
-
- if (charSet != null)
- Encoding = CharSetMap.GetEncoding( version, charSet );
- else
- Encoding = CharSetMap.GetEncoding( version, "latin1" );
- }
+ {
+ cmd.CommandText = "SET character_set_results=NULL";
+ object clientCharSet = serverProps["character_set_client"];
+ object connCharSet = serverProps["character_set_connection"];
+ if ((clientCharSet != null && clientCharSet.ToString() != charSet) ||
+ (connCharSet != null && connCharSet.ToString() != charSet))
+ {
+ cmd.CommandText = "SET NAMES " + charSet + ";" + cmd.CommandText;
+ }
+ cmd.ExecuteNonQuery();
+ }
+ if (charSet != null)
+ Encoding = CharSetMap.GetEncoding( version, charSet );
+ else
+ Encoding = CharSetMap.GetEncoding( version, "latin1" );
+ }
+
/// <summary>
/// Loads all the current character set names and ids for this server
/// into the charSets hashtable
@@ -226,77 +226,77 @@
MySqlCommand cmd = new MySqlCommand("SHOW COLLATION", connection);
MySqlDataReader reader = null;
- // now we load all the currently active collations
- try
- {
- reader = cmd.ExecuteReader();
+ // now we load all the currently active collations
+ try
+ {
+ reader = cmd.ExecuteReader();
charSets = new Hashtable();
- while (reader.Read())
- {
- charSets[ Convert.ToInt32(reader["id"], System.Globalization.NumberFormatInfo.InvariantInfo) ] =
- reader.GetString(reader.GetOrdinal("charset"));
- }
- }
+ while (reader.Read())
+ {
+ charSets[ Convert.ToInt32(reader["id"], System.Globalization.NumberFormatInfo.InvariantInfo) ] =
+ reader.GetString(reader.GetOrdinal("charset"));
+ }
+ }
catch (Exception ex)
- {
- Logger.LogException(ex);
- throw;
- }
+ {
+ Logger.LogException(ex);
+ throw;
+ }
finally
- {
- if (reader != null) reader.Close();
- }
+ {
+ if (reader != null) reader.Close();
+ }
}
public void ReportWarnings()
- {
- ArrayList errors = new ArrayList();
-
- MySqlCommand cmd = new MySqlCommand("SHOW WARNINGS", connection);
- MySqlDataReader reader = null;
+ {
+ ArrayList errors = new ArrayList();
+
+ MySqlCommand cmd = new MySqlCommand("SHOW WARNINGS", connection);
+ MySqlDataReader reader = null;
try
- {
- reader = cmd.ExecuteReader();
+ {
+ reader = cmd.ExecuteReader();
while (reader.Read())
- {
- errors.Add(new MySqlError(reader.GetString(0),
- reader.GetInt32(1), reader.GetString(2)));
- }
- reader.Close();
-
- hasWarnings = false;
- // MySQL resets warnings before each statement, so a batch could indicate
- // warnings when there aren't any
- if (errors.Count == 0) return;
-
+ {
+ errors.Add(new MySqlError(reader.GetString(0),
+ reader.GetInt32(1), reader.GetString(2)));
+ }
+ reader.Close();
+
+ hasWarnings = false;
+ // MySQL resets warnings before each statement, so a batch could indicate
+ // warnings when there aren't any
+ if (errors.Count == 0) return;
+
MySqlInfoMessageEventArgs args = new MySqlInfoMessageEventArgs();
args.errors = (MySqlError[])errors.ToArray(typeof(MySqlError));
if (connection != null)
connection.OnInfoMessage( args );
-
- }
+
+ }
catch (Exception)
- {
- throw;
- }
+ {
+ throw;
+ }
finally
- {
- if (reader != null) reader.Close();
- }
- }
+ {
+ if (reader != null) reader.Close();
+ }
+ }
#region Abstract Methods
- public abstract bool SupportsBatch { get; }
- public abstract void SetDatabase( string dbName );
+ public abstract bool SupportsBatch { get; }
+ public abstract void SetDatabase( string dbName );
public abstract PreparedStatement Prepare( string sql, string[] names );
public abstract void Reset();
public abstract CommandResult SendQuery( byte[] bytes, int length, bool consume );
- public abstract long ReadResult( ref long affectedRows, ref long lastInsertId );
+ public abstract long ReadResult( ref long affectedRows, ref long lastInsertId );
public abstract bool OpenDataRow(int fieldCount, bool isBinary);
public abstract MySqlValue ReadFieldValue( int index, MySqlField field, MySqlValue value );
- public abstract CommandResult ExecuteStatement( byte[] bytes );
- public abstract void SkipField(MySqlValue valObject );
+ public abstract CommandResult ExecuteStatement( byte[] bytes );
+ public abstract void SkipField(MySqlValue valObject );
public abstract void ReadFieldMetadata( int count, ref MySqlField[] fields );
public abstract bool Ping();
Modified: branches/1.0/mysqlclient/datareader.cs
===================================================================
--- branches/1.0/mysqlclient/datareader.cs 2006-05-18 19:08:04 UTC (rev 235)
+++ branches/1.0/mysqlclient/datareader.cs 2006-05-18 19:53:53 UTC (rev 236)
@@ -132,6 +132,13 @@
connection.Reader = null;
command.Consume();
+ // if our batch resulted in warnings, then report them now
+ // this is suboptimal but we have to report them here since
+ // pulling warnings from the server requires a reader and
+ // we can't have more than one reader open at one time.
+ if (connection.driver.HasWarnings)
+ connection.driver.ReportWarnings();
+
if (0 != (commandBehavior & CommandBehavior.CloseConnection))
connection.Close();
}
| Thread |
|---|
| • Connector/NET commit: r236 - in branches/1.0: . TestSuite mysqlclient | rburnett | 18 May |