Removed:
trunk/mysqlclient/Types/NumberFormat.cs
Modified:
trunk/TestSuite/AssemblyInfo.cs
trunk/TestSuite/AsyncTests.cs
trunk/TestSuite/CursorTests.cs
trunk/TestSuite/DataReaderTests.cs
trunk/TestSuite/InterfaceTests.cs
trunk/TestSuite/ParameterTests.cs
trunk/TestSuite/PerfMonTests.cs
trunk/TestSuite/SchemaTests.cs
trunk/TestSuite/StoredProcedure.cs
trunk/TestSuite/Syntax.cs
trunk/TestSuite/UsageAdvisor.cs
trunk/mysqlclient/MySql.Data.2005.csproj
trunk/mysqlclient/Types/MetaData.cs
trunk/mysqlclient/Types/MySqlBinary.cs
trunk/mysqlclient/Types/MySqlByte.cs
trunk/mysqlclient/Types/MySqlTime.cs
trunk/mysqlclient/common/SHA1.cs
trunk/mysqlclient/common/WinCE.cs
Log:
updated GPL license text
Modified: trunk/TestSuite/AssemblyInfo.cs
===================================================================
--- trunk/TestSuite/AssemblyInfo.cs 2006-07-30 15:48:19 UTC (rev 285)
+++ trunk/TestSuite/AssemblyInfo.cs 2006-07-30 16:36:21 UTC (rev 286)
@@ -31,7 +31,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("MySQL AB")]
[assembly: AssemblyProduct("")]
-[assembly: AssemblyCopyright("Copyright 2004-2005, MySQL AB")]
+[assembly: AssemblyCopyright("Copyright 2004-2006, MySQL AB")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -46,7 +46,7 @@
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
-[assembly: AssemblyVersion("1.0.7.*")]
+[assembly: AssemblyVersion("5.0.0")]
//
// In order to sign your assembly you must specify a key to use. Refer to the
Modified: trunk/TestSuite/AsyncTests.cs
===================================================================
--- trunk/TestSuite/AsyncTests.cs 2006-07-30 15:48:19 UTC (rev 285)
+++ trunk/TestSuite/AsyncTests.cs 2006-07-30 16:36:21 UTC (rev 286)
@@ -1,4 +1,4 @@
-// Copyright (C) 2004 MySQL AB
+// 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
Modified: trunk/TestSuite/CursorTests.cs
===================================================================
--- trunk/TestSuite/CursorTests.cs 2006-07-30 15:48:19 UTC (rev 285)
+++ trunk/TestSuite/CursorTests.cs 2006-07-30 16:36:21 UTC (rev 286)
@@ -1,4 +1,4 @@
-// Copyright (C) 2004 MySQL AB
+// 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
@@ -29,7 +29,7 @@
/// <summary>
/// Summary description for BlobTests.
/// </summary>
- [NUnit.Framework.TestFixture]
+ [TestFixture]
public class CursorTests : BaseTest
{
[TestFixtureSetUp]
Modified: trunk/TestSuite/DataReaderTests.cs
===================================================================
--- trunk/TestSuite/DataReaderTests.cs 2006-07-30 15:48:19 UTC (rev 285)
+++ trunk/TestSuite/DataReaderTests.cs 2006-07-30 16:36:21 UTC (rev 286)
@@ -1,827 +1,827 @@
-// 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.Data;
-using MySql.Data.MySqlClient;
-using MySql.Data.Types;
-using NUnit.Framework;
-
-namespace MySql.Data.MySqlClient.Tests
-{
- /// <summary>
- /// Summary description for ConnectionTests.
- /// </summary>
- [TestFixture]
- public class DataReaderTests : BaseTest
- {
- [TestFixtureSetUp]
- public void TestFixtureSetUp()
- {
- Open();
- }
-
- [TestFixtureTearDown]
- public void TestFixtureTearDown()
- {
- Close();
- }
-
- [SetUp]
- protected override void Setup()
- {
- base.Setup();
- execSQL("DROP TABLE IF EXISTS Test");
- execSQL("CREATE TABLE Test (id INT NOT NULL, name VARCHAR(100), d DATE, dt DATETIME, b1 LONGBLOB, PRIMARY KEY(id))");
- }
-
-
- [Test]
- public void TestMultipleResultsets()
- {
- MySqlDataReader reader =null;
- try
- {
- MySqlCommand cmd = new MySqlCommand("", conn);
- // insert 100 records
- cmd.CommandText = "INSERT INTO Test (id,name) VALUES (?id, 'test')";
- cmd.Parameters.Add( new MySqlParameter("?id", 1));
- for (int i=1; i <= 100; i++)
- {
- cmd.Parameters[0].Value = i;
- cmd.ExecuteNonQuery();
- }
-
- // execute it one time
- cmd = new MySqlCommand("SELECT id FROM Test WHERE id<50; SELECT * FROM Test WHERE id >= 50;", conn);
- reader = cmd.ExecuteReader();
- Assert.IsNotNull( reader );
- Assert.AreEqual( true, reader.HasRows );
- Assert.IsTrue( reader.Read() );
- Assert.AreEqual( 1, reader.FieldCount );
- Assert.IsTrue( reader.NextResult() );
- Assert.AreEqual( true, reader.HasRows );
- Assert.AreEqual( 5, reader.FieldCount );
- reader.Close();
-
- // now do it again
- reader = cmd.ExecuteReader();
- Assert.IsNotNull( reader );
- Assert.AreEqual( true, reader.HasRows );
- Assert.IsTrue( reader.Read() );
- Assert.AreEqual( 1, reader.FieldCount );
- Assert.IsTrue( reader.NextResult() );
- Assert.AreEqual( true, reader.HasRows );
- Assert.AreEqual( 5, reader.FieldCount );
- reader.Close();
- }
- catch (Exception ex)
- {
- Assert.Fail( ex.Message );
- }
- finally
- {
- if (reader != null) reader.Close();
- }
- }
-
- [Test]
- public void TestNotReadingResultset()
- {
- for (int x=0; x < 10; x++)
- {
- MySqlConnection c = new MySqlConnection( conn.ConnectionString +
- ";pooling=false" );
- c.Open();
-
- MySqlCommand cmd = new MySqlCommand(
- "INSERT INTO Test (id, name, b1) VALUES(?val, 'Test', NULL)", c);
- cmd.Parameters.Add(new MySqlParameter("?val", x));
- int affected = cmd.ExecuteNonQuery();
- Assert.AreEqual(1, affected);
-
- cmd = new MySqlCommand("SELECT * FROM Test", c);
- cmd.ExecuteReader();
- c.Close();
- }
- }
-
- [Test]
- public void GetBytes()
- {
- int len = 50000;
- byte[] bytes = Utils.CreateBlob(len);
- MySqlCommand cmd = new MySqlCommand(
- "INSERT INTO Test (id, name, b1) VALUES(1, 'Test', ?b1)", conn);
- cmd.Parameters.Add("?b1", bytes);
- cmd.ExecuteNonQuery();
-
- cmd.CommandText = "SELECT * FROM Test";
- MySqlDataReader reader = null;
- try
- {
- reader = cmd.ExecuteReader();
- reader.Read();
-
- long sizeBytes = reader.GetBytes(4, 0, null, 0, 0);
- Assert.AreEqual(len, sizeBytes);
-
- byte[] buff1 = new byte[len/2];
- byte[] buff2 = new byte[len - (len/2)];
- long buff1cnt = reader.GetBytes(4, 0, buff1, 0, len /2);
- long buff2cnt = reader.GetBytes(4, buff1cnt, buff2, 0, buff2.Length);
- Assert.AreEqual(buff1.Length, buff1cnt);
- Assert.AreEqual(buff2.Length, buff2cnt);
-
- for (int i=0; i<buff1.Length; i++)
- Assert.AreEqual(bytes[i], buff1[i]);
-
- for (int i=0; i<buff2.Length; i++)
- Assert.AreEqual(bytes[buff1.Length + i], buff2[i]);
-
- reader.Close();
-
- // now check with sequential access
- reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
- Assert.IsTrue(reader.Read());
- int mylen = len;
- byte[] buff = new byte[8192];
- int startIndex = 0;
- while (mylen > 0)
- {
- int readLen = Math.Min(mylen, buff.Length);
- int retVal = (int)reader.GetBytes(4, startIndex, buff, 0, readLen);
- Assert.AreEqual(readLen, retVal);
- for (int i=0; i < readLen; i++)
- Assert.AreEqual(bytes[startIndex+i], buff[i]);
- startIndex += readLen;
- mylen -= readLen;
- }
-
- }
- catch (Exception ex)
- {
- Assert.Fail( ex.Message );
- }
- finally
- {
- if (reader != null) reader.Close();
- }
-
- }
-
- [Test]
- public void TestSingleResultSetBehavior()
- {
- execSQL("INSERT INTO Test (id, name, b1) VALUES (1, 'Test1', NULL)");
- execSQL("INSERT INTO Test (id, name, b1) VALUES (2, 'Test1', NULL)");
-
- MySqlCommand cmd = new MySqlCommand(
- "SELECT * FROM Test WHERE id=1; SELECT * FROM Test WHERE id=2", conn);
- MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleResult);
- bool result = reader.Read();
- Assert.AreEqual(true, result);
-
- result = reader.NextResult();
- Assert.AreEqual(false, result);
-
- reader.Close();
- }
-
- [Test]
- public void GetSchema()
- {
- string sql = "CREATE TABLE test2(id INT UNSIGNED AUTO_INCREMENT " +
- "NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id))";
-
- execSQL("DROP TABLE IF EXISTS test2");
- execSQL(sql);
- execSQL("INSERT INTO test2 VALUES(1,'Test')");
-
- MySqlDataReader reader = null;
-
- try
- {
- MySqlCommand cmd = new MySqlCommand("SELECT * FROM test2", conn);
- reader = cmd.ExecuteReader();
- DataTable dt = reader.GetSchemaTable();
- Assert.AreEqual(true, dt.Rows[0]["IsAutoIncrement"], "Checking auto increment");
- Assert.AreEqual(true, dt.Rows[0]["IsUnique"], "Checking IsUnique");
- Assert.AreEqual(false, dt.Rows[0]["AllowDBNull"], "Checking AllowDBNull");
- Assert.AreEqual(false, dt.Rows[1]["AllowDBNull"], "Checking AllowDBNull");
- }
- catch (Exception ex)
- {
- Assert.Fail(ex.Message);
- }
- finally
- {
- if (reader != null) reader.Close();
- }
-
- execSQL("DROP TABLE IF EXISTS test2");
- }
-
- [Test]
- public void CloseConnectionBehavior()
- {
- execSQL("INSERT INTO Test(id,name) VALUES(1,'test')");
-
- MySqlConnection c2 = new MySqlConnection(conn.ConnectionString);
- c2.Open();
- MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", c2);
- MySqlDataReader reader = null;
- try
- {
- reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
- Assert.IsTrue(reader.Read());
- reader.Close();
- Assert.IsTrue(c2.State == ConnectionState.Closed);
- }
- catch (Exception ex)
- {
- Assert.Fail(ex.Message);
- }
- finally
- {
- if (reader != null) reader.Close();
- if (c2.State == ConnectionState.Closed) c2.Open();
- }
- }
-
- [Test]
- public void SingleRowBehavior()
- {
- execSQL("INSERT INTO Test(id,name) VALUES(1,'test1')");
- execSQL("INSERT INTO Test(id,name) VALUES(2,'test2')");
- execSQL("INSERT INTO Test(id,name) VALUES(3,'test3')");
-
- MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", conn);
- MySqlDataReader reader = null;
- try
- {
- reader = cmd.ExecuteReader(CommandBehavior.SingleRow);
- Assert.IsTrue(reader.Read(), "First read");
- Assert.IsFalse(reader.Read(), "Second read");
- Assert.IsFalse(reader.NextResult(), "Trying NextResult");
- reader.Close();
-
- cmd.CommandText = "SELECT * FROM test where id=1";
- reader = cmd.ExecuteReader(CommandBehavior.SingleRow);
- Assert.IsTrue(reader.Read());
- Assert.AreEqual("test1", reader.GetString(1));
- Assert.IsFalse(reader.Read());
- Assert.IsFalse(reader.NextResult());
- reader.Close();
-
- reader = null;
- }
- catch (Exception ex)
- {
- Assert.Fail( ex.Message );
- }
- finally
- {
- if (reader != null) reader.Close();
- }
- }
-
- [Test]
- public void SingleRowBehaviorWithLimit()
- {
- execSQL("INSERT INTO Test(id,name) VALUES(1,'test1')");
- execSQL("INSERT INTO Test(id,name) VALUES(2,'test2')");
- execSQL("INSERT INTO Test(id,name) VALUES(3,'test3')");
-
- MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test LIMIT 2", conn);
- MySqlDataReader reader = null;
- try
- {
- reader = cmd.ExecuteReader(CommandBehavior.SingleRow);
- Assert.IsTrue(reader.Read(), "First read");
- Assert.IsFalse(reader.Read(), "Second read");
- Assert.IsFalse(reader.NextResult(), "Trying NextResult");
- reader.Close();
-
- reader = cmd.ExecuteReader(CommandBehavior.SingleRow);
- Assert.IsTrue(reader.Read(), "First read");
- Assert.IsFalse(reader.Read(), "Second read");
- Assert.IsFalse(reader.NextResult(), "Trying NextResult");
- reader.Close();
-
- reader = cmd.ExecuteReader(CommandBehavior.SingleRow);
- Assert.IsTrue(reader.Read(), "First read");
- Assert.IsFalse(reader.Read(), "Second read");
- Assert.IsFalse(reader.NextResult(), "Trying NextResult");
- reader.Close();
- }
- catch (Exception ex)
- {
- Assert.Fail( ex.Message );
- }
- finally
- {
- if (reader != null) reader.Close();
- }
- }
-
- [Test]
- public void SimpleSingleRow()
- {
- execSQL("INSERT INTO Test(id,name) VALUES(1,'test1')");
-
- MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", conn);
- MySqlDataReader reader = null;
- try
- {
- reader = cmd.ExecuteReader();
- Assert.IsTrue(reader.Read(), "First read");
- Assert.AreEqual(1, reader.GetInt32(0));
- Assert.AreEqual("test1", reader.GetString(1));
- Assert.IsFalse(reader.Read(), "Second read");
- Assert.IsFalse(reader.NextResult(), "Trying NextResult");
- }
- catch (Exception ex)
- {
- Assert.Fail( ex.Message );
- }
- finally
- {
- if (reader != null) reader.Close();
- }
- }
-
- [Test]
- public void ConsecutiveNulls()
- {
- execSQL("INSERT INTO Test (id, name) VALUES (1, 'Test')");
- execSQL("INSERT INTO Test (id, name) VALUES (2, NULL)");
- execSQL("INSERT INTO Test (id, name) VALUES (3, 'Test2')");
-
- MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", conn);
- MySqlDataReader reader = null;
- try
- {
- reader = cmd.ExecuteReader();
- reader.Read();
- Assert.AreEqual(1, reader.GetValue(0));
- Assert.AreEqual("Test", reader.GetValue(1));
- Assert.AreEqual("Test", reader.GetString(1));
- reader.Read();
- Assert.AreEqual(2, reader.GetValue(0));
+// 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.Data;
+using MySql.Data.MySqlClient;
+using MySql.Data.Types;
+using NUnit.Framework;
+
+namespace MySql.Data.MySqlClient.Tests
+{
+ /// <summary>
+ /// Summary description for ConnectionTests.
+ /// </summary>
+ [TestFixture]
+ public class DataReaderTests : BaseTest
+ {
+ [TestFixtureSetUp]
+ public void TestFixtureSetUp()
+ {
+ Open();
+ }
+
+ [TestFixtureTearDown]
+ public void TestFixtureTearDown()
+ {
+ Close();
+ }
+
+ [SetUp]
+ protected override void Setup()
+ {
+ base.Setup();
+ execSQL("DROP TABLE IF EXISTS Test");
+ execSQL("CREATE TABLE Test (id INT NOT NULL, name VARCHAR(100), d DATE, dt DATETIME, b1 LONGBLOB, PRIMARY KEY(id))");
+ }
+
+
+ [Test]
+ public void TestMultipleResultsets()
+ {
+ MySqlDataReader reader =null;
+ try
+ {
+ MySqlCommand cmd = new MySqlCommand("", conn);
+ // insert 100 records
+ cmd.CommandText = "INSERT INTO Test (id,name) VALUES (?id, 'test')";
+ cmd.Parameters.Add( new MySqlParameter("?id", 1));
+ for (int i=1; i <= 100; i++)
+ {
+ cmd.Parameters[0].Value = i;
+ cmd.ExecuteNonQuery();
+ }
+
+ // execute it one time
+ cmd = new MySqlCommand("SELECT id FROM Test WHERE id<50; SELECT * FROM Test WHERE id >= 50;", conn);
+ reader = cmd.ExecuteReader();
+ Assert.IsNotNull( reader );
+ Assert.AreEqual( true, reader.HasRows );
+ Assert.IsTrue( reader.Read() );
+ Assert.AreEqual( 1, reader.FieldCount );
+ Assert.IsTrue( reader.NextResult() );
+ Assert.AreEqual( true, reader.HasRows );
+ Assert.AreEqual( 5, reader.FieldCount );
+ reader.Close();
+
+ // now do it again
+ reader = cmd.ExecuteReader();
+ Assert.IsNotNull( reader );
+ Assert.AreEqual( true, reader.HasRows );
+ Assert.IsTrue( reader.Read() );
+ Assert.AreEqual( 1, reader.FieldCount );
+ Assert.IsTrue( reader.NextResult() );
+ Assert.AreEqual( true, reader.HasRows );
+ Assert.AreEqual( 5, reader.FieldCount );
+ reader.Close();
+ }
+ catch (Exception ex)
+ {
+ Assert.Fail( ex.Message );
+ }
+ finally
+ {
+ if (reader != null) reader.Close();
+ }
+ }
+
+ [Test]
+ public void TestNotReadingResultset()
+ {
+ for (int x=0; x < 10; x++)
+ {
+ MySqlConnection c = new MySqlConnection( conn.ConnectionString +
+ ";pooling=false" );
+ c.Open();
+
+ MySqlCommand cmd = new MySqlCommand(
+ "INSERT INTO Test (id, name, b1) VALUES(?val, 'Test', NULL)", c);
+ cmd.Parameters.Add(new MySqlParameter("?val", x));
+ int affected = cmd.ExecuteNonQuery();
+ Assert.AreEqual(1, affected);
+
+ cmd = new MySqlCommand("SELECT * FROM Test", c);
+ cmd.ExecuteReader();
+ c.Close();
+ }
+ }
+
+ [Test]
+ public void GetBytes()
+ {
+ int len = 50000;
+ byte[] bytes = Utils.CreateBlob(len);
+ MySqlCommand cmd = new MySqlCommand(
+ "INSERT INTO Test (id, name, b1) VALUES(1, 'Test', ?b1)", conn);
+ cmd.Parameters.Add("?b1", bytes);
+ cmd.ExecuteNonQuery();
+
+ cmd.CommandText = "SELECT * FROM Test";
+ MySqlDataReader reader = null;
+ try
+ {
+ reader = cmd.ExecuteReader();
+ reader.Read();
+
+ long sizeBytes = reader.GetBytes(4, 0, null, 0, 0);
+ Assert.AreEqual(len, sizeBytes);
+
+ byte[] buff1 = new byte[len/2];
+ byte[] buff2 = new byte[len - (len/2)];
+ long buff1cnt = reader.GetBytes(4, 0, buff1, 0, len /2);
+ long buff2cnt = reader.GetBytes(4, buff1cnt, buff2, 0, buff2.Length);
+ Assert.AreEqual(buff1.Length, buff1cnt);
+ Assert.AreEqual(buff2.Length, buff2cnt);
+
+ for (int i=0; i<buff1.Length; i++)
+ Assert.AreEqual(bytes[i], buff1[i]);
+
+ for (int i=0; i<buff2.Length; i++)
+ Assert.AreEqual(bytes[buff1.Length + i], buff2[i]);
+
+ reader.Close();
+
+ // now check with sequential access
+ reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
+ Assert.IsTrue(reader.Read());
+ int mylen = len;
+ byte[] buff = new byte[8192];
+ int startIndex = 0;
+ while (mylen > 0)
+ {
+ int readLen = Math.Min(mylen, buff.Length);
+ int retVal = (int)reader.GetBytes(4, startIndex, buff, 0, readLen);
+ Assert.AreEqual(readLen, retVal);
+ for (int i=0; i < readLen; i++)
+ Assert.AreEqual(bytes[startIndex+i], buff[i]);
+ startIndex += readLen;
+ mylen -= readLen;
+ }
+
+ }
+ catch (Exception ex)
+ {
+ Assert.Fail( ex.Message );
+ }
+ finally
+ {
+ if (reader != null) reader.Close();
+ }
+
+ }
+
+ [Test]
+ public void TestSingleResultSetBehavior()
+ {
+ execSQL("INSERT INTO Test (id, name, b1) VALUES (1, 'Test1', NULL)");
+ execSQL("INSERT INTO Test (id, name, b1) VALUES (2, 'Test1', NULL)");
+
+ MySqlCommand cmd = new MySqlCommand(
+ "SELECT * FROM Test WHERE id=1; SELECT * FROM Test WHERE id=2", conn);
+ MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleResult);
+ bool result = reader.Read();
+ Assert.AreEqual(true, result);
+
+ result = reader.NextResult();
+ Assert.AreEqual(false, result);
+
+ reader.Close();
+ }
+
+ [Test]
+ public void GetSchema()
+ {
+ string sql = "CREATE TABLE test2(id INT UNSIGNED AUTO_INCREMENT " +
+ "NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id))";
+
+ execSQL("DROP TABLE IF EXISTS test2");
+ execSQL(sql);
+ execSQL("INSERT INTO test2 VALUES(1,'Test')");
+
+ MySqlDataReader reader = null;
+
+ try
+ {
+ MySqlCommand cmd = new MySqlCommand("SELECT * FROM test2", conn);
+ reader = cmd.ExecuteReader();
+ DataTable dt = reader.GetSchemaTable();
+ Assert.AreEqual(true, dt.Rows[0]["IsAutoIncrement"], "Checking auto increment");
+ Assert.AreEqual(true, dt.Rows[0]["IsUnique"], "Checking IsUnique");
+ Assert.AreEqual(false, dt.Rows[0]["AllowDBNull"], "Checking AllowDBNull");
+ Assert.AreEqual(false, dt.Rows[1]["AllowDBNull"], "Checking AllowDBNull");
+ }
+ catch (Exception ex)
+ {
+ Assert.Fail(ex.Message);
+ }
+ finally
+ {
+ if (reader != null) reader.Close();
+ }
+
+ execSQL("DROP TABLE IF EXISTS test2");
+ }
+
+ [Test]
+ public void CloseConnectionBehavior()
+ {
+ execSQL("INSERT INTO Test(id,name) VALUES(1,'test')");
+
+ MySqlConnection c2 = new MySqlConnection(conn.ConnectionString);
+ c2.Open();
+ MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", c2);
+ MySqlDataReader reader = null;
+ try
+ {
+ reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
+ Assert.IsTrue(reader.Read());
+ reader.Close();
+ Assert.IsTrue(c2.State == ConnectionState.Closed);
+ }
+ catch (Exception ex)
+ {
+ Assert.Fail(ex.Message);
+ }
+ finally
+ {
+ if (reader != null) reader.Close();
+ if (c2.State == ConnectionState.Closed) c2.Open();
+ }
+ }
+
+ [Test]
+ public void SingleRowBehavior()
+ {
+ execSQL("INSERT INTO Test(id,name) VALUES(1,'test1')");
+ execSQL("INSERT INTO Test(id,name) VALUES(2,'test2')");
+ execSQL("INSERT INTO Test(id,name) VALUES(3,'test3')");
+
+ MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", conn);
+ MySqlDataReader reader = null;
+ try
+ {
+ reader = cmd.ExecuteReader(CommandBehavior.SingleRow);
+ Assert.IsTrue(reader.Read(), "First read");
+ Assert.IsFalse(reader.Read(), "Second read");
+ Assert.IsFalse(reader.NextResult(), "Trying NextResult");
+ reader.Close();
+
+ cmd.CommandText = "SELECT * FROM test where id=1";
+ reader = cmd.ExecuteReader(CommandBehavior.SingleRow);
+ Assert.IsTrue(reader.Read());
+ Assert.AreEqual("test1", reader.GetString(1));
+ Assert.IsFalse(reader.Read());
+ Assert.IsFalse(reader.NextResult());
+ reader.Close();
+
+ reader = null;
+ }
+ catch (Exception ex)
+ {
+ Assert.Fail( ex.Message );
+ }
+ finally
+ {
+ if (reader != null) reader.Close();
+ }
+ }
+
+ [Test]
+ public void SingleRowBehaviorWithLimit()
+ {
+ execSQL("INSERT INTO Test(id,name) VALUES(1,'test1')");
+ execSQL("INSERT INTO Test(id,name) VALUES(2,'test2')");
+ execSQL("INSERT INTO Test(id,name) VALUES(3,'test3')");
+
+ MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test LIMIT 2", conn);
+ MySqlDataReader reader = null;
+ try
+ {
+ reader = cmd.ExecuteReader(CommandBehavior.SingleRow);
+ Assert.IsTrue(reader.Read(), "First read");
+ Assert.IsFalse(reader.Read(), "Second read");
+ Assert.IsFalse(reader.NextResult(), "Trying NextResult");
+ reader.Close();
+
+ reader = cmd.ExecuteReader(CommandBehavior.SingleRow);
+ Assert.IsTrue(reader.Read(), "First read");
+ Assert.IsFalse(reader.Read(), "Second read");
+ Assert.IsFalse(reader.NextResult(), "Trying NextResult");
+ reader.Close();
+
+ reader = cmd.ExecuteReader(CommandBehavior.SingleRow);
+ Assert.IsTrue(reader.Read(), "First read");
+ Assert.IsFalse(reader.Read(), "Second read");
+ Assert.IsFalse(reader.NextResult(), "Trying NextResult");
+ reader.Close();
+ }
+ catch (Exception ex)
+ {
+ Assert.Fail( ex.Message );
+ }
+ finally
+ {
+ if (reader != null) reader.Close();
+ }
+ }
+
+ [Test]
+ public void SimpleSingleRow()
+ {
+ execSQL("INSERT INTO Test(id,name) VALUES(1,'test1')");
+
+ MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", conn);
+ MySqlDataReader reader = null;
+ try
+ {
+ reader = cmd.ExecuteReader();
+ Assert.IsTrue(reader.Read(), "First read");
+ Assert.AreEqual(1, reader.GetInt32(0));
+ Assert.AreEqual("test1", reader.GetString(1));
+ Assert.IsFalse(reader.Read(), "Second read");
+ Assert.IsFalse(reader.NextResult(), "Trying NextResult");
+ }
+ catch (Exception ex)
+ {
+ Assert.Fail( ex.Message );
+ }
+ finally
+ {
+ if (reader != null) reader.Close();
+ }
+ }
+
+ [Test]
+ public void ConsecutiveNulls()
+ {
+ execSQL("INSERT INTO Test (id, name) VALUES (1, 'Test')");
+ execSQL("INSERT INTO Test (id, name) VALUES (2, NULL)");
+ execSQL("INSERT INTO Test (id, name) VALUES (3, 'Test2')");
+
+ MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", conn);
+ MySqlDataReader reader = null;
+ try
+ {
+ reader = cmd.ExecuteReader();
+ reader.Read();
+ Assert.AreEqual(1, reader.GetValue(0));
+ Assert.AreEqual("Test", reader.GetValue(1));
+ Assert.AreEqual("Test", reader.GetString(1));
+ reader.Read();
+ Assert.AreEqual(2, reader.GetValue(0));
Assert.AreEqual(DBNull.Value, reader.GetValue(1));
- reader.Read();
- Assert.AreEqual(3, reader.GetValue(0));
- Assert.AreEqual("Test2", reader.GetValue(1));
- Assert.AreEqual("Test2", reader.GetString(1));
- Assert.IsFalse(reader.Read());
- Assert.IsFalse(reader.NextResult());
- }
- catch (Exception ex)
- {
- Assert.Fail(ex.Message);
- }
- finally
- {
- if (reader != null) reader.Close();
- }
-
- }
-
- [Test]
- public void HungDataReader()
- {
- MySqlCommand cmd = new MySqlCommand("USE test; SHOW TABLES", conn);
- MySqlDataReader reader = null;
- try
- {
- reader = cmd.ExecuteReader();
- while (reader.Read())
- {
- reader.GetString(0);
- }
- }
- catch (Exception ex)
- {
- Assert.Fail(ex.Message);
- }
- finally
- {
- if (reader != null) reader.Close();
- }
- }
-
- /// <summary>
- /// Added test for IsDBNull from bug# 7399
- /// </summary>
- [Test]
- public void SequentialAccessBehavior()
- {
- execSQL("INSERT INTO Test(id,name) VALUES(1,'test1')");
-
- MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", conn);
- MySqlDataReader reader = null;
- try
- {
- reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
- Assert.IsTrue(reader.Read());
- Assert.IsFalse(reader.IsDBNull(0));
- int i = reader.GetInt32(0);
- string s = reader.GetString(1);
- Assert.AreEqual(1, i);
- Assert.AreEqual("test1", s);
-
- // this next line should throw an exception
- i = reader.GetInt32(0);
- Assert.Fail("This line should not execute");
- }
- catch (MySqlException) { }
- catch (Exception ex)
- {
- Assert.Fail(ex.Message);
- }
- finally
- {
- if (reader != null) reader.Close();
- }
- }
-
-
- [Test]
- public void ReadingTextFields()
- {
- execSQL("DROP TABLE IF EXISTS Test");
- execSQL("CREATE TABLE Test (id int, t1 TEXT)");
- execSQL("INSERT INTO Test VALUES (1, 'Text value')");
-
- MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", conn);
- MySqlDataReader reader = null;
- try
- {
- reader = cmd.ExecuteReader();
- reader.Read();
- string s = reader["t1"].ToString();
- Assert.AreEqual( "Text value", s );
- }
- catch (Exception ex)
- {
- Assert.Fail( ex.Message );
- }
- finally
- {
- if (reader != null) reader.Close();
- }
- }
-
- [Test]
- [ExpectedException( typeof(MySqlException) )]
- public void ReadingFieldsBeforeRead()
- {
- MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", conn);
- MySqlDataReader reader = cmd.ExecuteReader();
- try
- {
- reader.GetInt32(0);
- }
- catch (Exception)
- {
- throw;
- }
- finally
- {
- if (reader != null) reader.Close();
- }
- }
-
- [Test]
- public void GetChar()
- {
- execSQL("INSERT INTO Test (id, name) VALUES (1, 'a')");
- MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", conn);
- MySqlDataReader reader = null;
- try
- {
- reader = cmd.ExecuteReader();
- reader.Read();
- char achar = reader.GetChar( 1 );
- Assert.AreEqual( 'a', achar );
- }
- catch (Exception ex)
- {
- Assert.Fail( ex.Message );
- }
- finally
- {
- if (reader != null) reader.Close();
- }
- }
-
- [Test]
- public void ReaderOnNonQuery()
- {
- MySqlCommand cmd = new MySqlCommand("INSERT INTO Test (id,name) VALUES (1,'Test')", conn);
- MySqlDataReader reader = null;
- try
- {
- reader = cmd.ExecuteReader();
- Assert.IsFalse( reader.Read() );
- reader.Close();
-
- cmd.CommandText = "SELECT name FROM Test";
- object v = cmd.ExecuteScalar();
- Assert.AreEqual( "Test", v );
- }
- catch (Exception ex)
- {
- Assert.Fail( ex.Message );
- }
- finally
- {
- if (reader != null) reader.Close();
- }
- }
-
- [Test]
- public void TestManyDifferentResultsets()
- {
- MySqlDataReader reader =null;
- try
- {
- MySqlCommand cmd = new MySqlCommand("", conn);
- // insert 100 records
- cmd.CommandText = "INSERT INTO Test (id,name,dt,b1) VALUES (?id, 'test','2004-12-05 12:57:00','long blob data')";
- cmd.Parameters.Add( new MySqlParameter("?id", 1));
- for (int i=1; i <= 100; i++)
- {
- cmd.Parameters[0].Value = i;
- cmd.ExecuteNonQuery();
- }
-
- cmd = new MySqlCommand("SELECT id FROM Test WHERE id<?param1; "+
- "SELECT id,name FROM Test WHERE id = -50; "+
- "SELECT * FROM Test WHERE id >= ?param1; "+
- "SELECT id, dt, b1 FROM Test WHERE id = -50; "+
- "SELECT b1 FROM Test WHERE id = -50; "+
- "SELECT id, dt, b1 FROM Test WHERE id < ?param1; "+
- "SELECT b1 FROM Test WHERE id >= ?param1;", conn);
-
- cmd.Parameters.Add("?param1",50);
-
- reader = cmd.ExecuteReader();
-
- Assert.IsNotNull( reader );
-
- //First ResultSet, should have 49 rows.
- //SELECT id FROM test WHERE id<?param1;
- Assert.AreEqual( true, reader.HasRows );
- Assert.AreEqual( 1, reader.FieldCount );
- for (int i = 0; i < 49; i++)
- {
- Assert.IsTrue( reader.Read() );
- }
- Assert.AreEqual( false, reader.Read() );
-
- //Second ResultSet, should have no rows.
- //SELECT id,name FROM test WHERE id = -50;
- Assert.IsTrue( reader.NextResult() );
- Assert.AreEqual( false, reader.HasRows );
- Assert.AreEqual( 2, reader.FieldCount );
- Assert.AreEqual( false, reader.Read() );
-
-
- //Third ResultSet, should have 51 rows.
- //SELECT * FROM test WHERE id >= ?param1;
- Assert.IsTrue( reader.NextResult() );
- Assert.AreEqual( true, reader.HasRows );
- Assert.AreEqual( 5, reader.FieldCount );
- for (int i = 0; i < 51; i++)
- {
- Assert.IsTrue( reader.Read() );
- }
- Assert.AreEqual( false, reader.Read() );
-
-
- //Fourth ResultSet, should have no rows.
- //SELECT id, dt, b1 FROM test WHERE id = -50;
- Assert.IsTrue( reader.NextResult() );
- Assert.AreEqual( false, reader.HasRows );
- Assert.AreEqual( 3, reader.FieldCount ); //Will Fail if uncommented expected 3 returned 5
- Assert.AreEqual( false, reader.Read() );
-
- //Fifth ResultSet, should have no rows.
- //SELECT b1 FROM test WHERE id = -50;
- Assert.IsTrue( reader.NextResult() );
- Assert.AreEqual( false, reader.HasRows );
- Assert.AreEqual( 1, reader.FieldCount ); //Will Fail if uncommented expected 1 returned 5
- Assert.AreEqual( false, reader.Read() );
-
- //Sixth ResultSet, should have 49 rows.
- //SELECT id, dt, b1 FROM test WHERE id < ?param1;
- Assert.IsTrue( reader.NextResult() );
- Assert.AreEqual( true, reader.HasRows );
- Assert.AreEqual( 3, reader.FieldCount ); //Will Fail if uncommented expected 3 returned 5
- for (int i = 0; i < 49; i++)
- {
- Assert.IsTrue( reader.Read() );
- }
- Assert.AreEqual( false, reader.Read() );
-
- //Seventh ResultSet, should have 51 rows.
- //SELECT b1 FROM test WHERE id >= ?param1;
- Assert.IsTrue( reader.NextResult() );
- Assert.AreEqual( true, reader.HasRows );
- Assert.AreEqual( 1, reader.FieldCount ); //Will Fail if uncommented expected 1 returned 5
- for (int i = 0; i < 51; i++)
- {
- Assert.IsTrue( reader.Read() );
- }
- Assert.AreEqual( false, reader.Read() );
- }
- catch (Exception ex)
- {
- Assert.Fail( ex.Message );
- }
- finally
- {
- if (reader != null) reader.Close();
- }
- }
-
-
- [Test]
- public void TestMultipleResultsWithQueryCacheOn()
- {
- execSQL("SET SESSION query_cache_type = ON");
- execSQL("INSERT INTO Test (id,name) VALUES (1, 'Test')");
- execSQL("INSERT INTO Test (id,name) VALUES (51, 'Test')");
-
-
- MySqlDataReader reader =null;
-
- try
- {
-
- // execute it one time
- MySqlCommand cmd = new MySqlCommand("SELECT id FROM Test WHERE id<50; SELECT * FROM Test WHERE id >= 50;", conn);
-
- reader = cmd.ExecuteReader();
-
- Assert.IsNotNull( reader );
- Assert.AreEqual( true, reader.HasRows );
- Assert.IsTrue( reader.Read() );
- Assert.AreEqual( 1, reader.FieldCount );
- Assert.IsTrue( reader.NextResult() );
- Assert.AreEqual( true, reader.HasRows );
- Assert.AreEqual( 5, reader.FieldCount );
-
- reader.Close();
-
- // now do it again
- reader = cmd.ExecuteReader();
- Assert.IsNotNull( reader );
- Assert.AreEqual( true, reader.HasRows );
- Assert.IsTrue( reader.Read() );
- Assert.AreEqual( 1, reader.FieldCount );
- Assert.IsTrue( reader.NextResult() );
- Assert.AreEqual( true, reader.HasRows );
- Assert.AreEqual( 5, reader.FieldCount );
-
- reader.Close();
- }
- catch (Exception ex)
- {
- Assert.Fail( ex.Message );
- }
- finally
- {
- if (reader != null) reader.Close();
- }
- }
-
- /// <summary>
- /// Bug #8630 Executing a query with the SchemaOnly option reads the entire resultset
- /// </summary>
- [Test]
- public void SchemaOnly()
- {
- execSQL("INSERT INTO Test (id,name) VALUES(1,'test1')");
- execSQL("INSERT INTO Test (id,name) VALUES(2,'test2')");
- execSQL("INSERT INTO Test (id,name) VALUES(3,'test3')");
-
- MySqlCommand cmd = new MySqlCommand("SELECT * FROM test", conn);
- MySqlDataReader reader = null;
- try
- {
- reader = cmd.ExecuteReader(CommandBehavior.SchemaOnly);
- DataTable table = reader.GetSchemaTable();
- Assert.AreEqual(5, table.Rows.Count);
- Assert.AreEqual(22, table.Columns.Count);
- Assert.IsFalse(reader.Read());
- }
- catch (Exception ex)
- {
- Assert.Fail(ex.Message);
- }
- finally
- {
- if (reader != null) reader.Close();
- }
- }
-
- /// <summary>
- /// Bug #9237 MySqlDataReader.AffectedRecords not set to -1
- /// </summary>
- [Test]
- public void AffectedRows()
- {
- MySqlCommand cmd = new MySqlCommand("SHOW TABLES", conn);
- try
- {
- using (MySqlDataReader reader = cmd.ExecuteReader())
- {
- reader.Read();
- reader.Close();
- Assert.AreEqual(-1, reader.RecordsAffected);
- }
- }
- catch (Exception ex)
- {
- Assert.Fail(ex.Message);
- }
- }
-
- /// <summary>
- /// Bug #11873 Invalid timestamp in query produces incorrect reader exception
- /// </summary>
- [Test]
- public void InvalidTimestamp()
- {
- execSQL("DROP TABLE IF EXISTS test");
- execSQL("CREATE TABLE test (tm TIMESTAMP)");
- execSQL("INSERT INTO test VALUES (NULL)");
-
- MySqlCommand cmd = new MySqlCommand("SELECT * FROM test WHERE tm = '7/1/2005 12:00:00 AM'", conn);
- MySqlDataReader reader = null;
- try
- {
- reader = cmd.ExecuteReader();
- }
- catch (Exception ex)
- {
- Assert.Fail(ex.Message);
- }
- finally
- {
- if (reader != null) reader.Close();
- }
- }
-
- /// <summary>
- /// Bug #19294 IDataRecord.GetString method should return null for null values
- /// </summary>
- [Test]
- public void GetStringOnNull()
- {
- execSQL("DROP TABLE IF EXISTS test");
- execSQL("CREATE TABLE test (id int, PRIMARY KEY(id))");
- MySqlCommand cmd = new MySqlCommand("SHOW INDEX FROM test FROM test", conn);
- MySqlDataReader reader = null;
- try
- {
- reader = cmd.ExecuteReader();
- reader.Read();
- string s = reader.GetString(reader.GetOrdinal("Sub_part"));
- Assert.Fail("We should not get here");
- }
- catch (System.Data.SqlTypes.SqlNullValueException)
- {
- }
- catch (Exception ex)
- {
- Assert.Fail(ex.Message);
- }
- finally
- {
- if (reader != null)
- reader.Close();
- }
- }
- }
-}
+ reader.Read();
+ Assert.AreEqual(3, reader.GetValue(0));
+ Assert.AreEqual("Test2", reader.GetValue(1));
+ Assert.AreEqual("Test2", reader.GetString(1));
+ Assert.IsFalse(reader.Read());
+ Assert.IsFalse(reader.NextResult());
+ }
+ catch (Exception ex)
+ {
+ Assert.Fail(ex.Message);
+ }
+ finally
+ {
+ if (reader != null) reader.Close();
+ }
+
+ }
+
+ [Test]
+ public void HungDataReader()
+ {
+ MySqlCommand cmd = new MySqlCommand("USE test; SHOW TABLES", conn);
+ MySqlDataReader reader = null;
+ try
+ {
+ reader = cmd.ExecuteReader();
+ while (reader.Read())
+ {
+ reader.GetString(0);
+ }
+ }
+ catch (Exception ex)
+ {
+ Assert.Fail(ex.Message);
+ }
+ finally
+ {
+ if (reader != null) reader.Close();
+ }
+ }
+
+ /// <summary>
+ /// Added test for IsDBNull from bug# 7399
+ /// </summary>
+ [Test]
+ public void SequentialAccessBehavior()
+ {
+ execSQL("INSERT INTO Test(id,name) VALUES(1,'test1')");
+
+ MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", conn);
+ MySqlDataReader reader = null;
+ try
+ {
+ reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
+ Assert.IsTrue(reader.Read());
+ Assert.IsFalse(reader.IsDBNull(0));
+ int i = reader.GetInt32(0);
+ string s = reader.GetString(1);
+ Assert.AreEqual(1, i);
+ Assert.AreEqual("test1", s);
+
+ // this next line should throw an exception
+ i = reader.GetInt32(0);
+ Assert.Fail("This line should not execute");
+ }
+ catch (MySqlException) { }
+ catch (Exception ex)
+ {
+ Assert.Fail(ex.Message);
+ }
+ finally
+ {
+ if (reader != null) reader.Close();
+ }
+ }
+
+
+ [Test]
+ public void ReadingTextFields()
+ {
+ execSQL("DROP TABLE IF EXISTS Test");
+ execSQL("CREATE TABLE Test (id int, t1 TEXT)");
+ execSQL("INSERT INTO Test VALUES (1, 'Text value')");
+
+ MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", conn);
+ MySqlDataReader reader = null;
+ try
+ {
+ reader = cmd.ExecuteReader();
+ reader.Read();
+ string s = reader["t1"].ToString();
+ Assert.AreEqual( "Text value", s );
+ }
+ catch (Exception ex)
+ {
+ Assert.Fail( ex.Message );
+ }
+ finally
+ {
+ if (reader != null) reader.Close();
+ }
+ }
+
+ [Test]
+ [ExpectedException( typeof(MySqlException) )]
+ public void ReadingFieldsBeforeRead()
+ {
+ MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", conn);
+ MySqlDataReader reader = cmd.ExecuteReader();
+ try
+ {
+ reader.GetInt32(0);
+ }
+ catch (Exception)
+ {
+ throw;
+ }
+ finally
+ {
+ if (reader != null) reader.Close();
+ }
+ }
+
+ [Test]
+ public void GetChar()
+ {
+ execSQL("INSERT INTO Test (id, name) VALUES (1, 'a')");
+ MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", conn);
+ MySqlDataReader reader = null;
+ try
+ {
+ reader = cmd.ExecuteReader();
+ reader.Read();
+ char achar = reader.GetChar( 1 );
+ Assert.AreEqual( 'a', achar );
+ }
+ catch (Exception ex)
+ {
+ Assert.Fail( ex.Message );
+ }
+ finally
+ {
+ if (reader != null) reader.Close();
+ }
+ }
+
+ [Test]
+ public void ReaderOnNonQuery()
+ {
+ MySqlCommand cmd = new MySqlCommand("INSERT INTO Test (id,name) VALUES (1,'Test')", conn);
+ MySqlDataReader reader = null;
+ try
+ {
+ reader = cmd.ExecuteReader();
+ Assert.IsFalse( reader.Read() );
+ reader.Close();
+
+ cmd.CommandText = "SELECT name FROM Test";
+ object v = cmd.ExecuteScalar();
+ Assert.AreEqual( "Test", v );
+ }
+ catch (Exception ex)
+ {
+ Assert.Fail( ex.Message );
+ }
+ finally
+ {
+ if (reader != null) reader.Close();
+ }
+ }
+
+ [Test]
+ public void TestManyDifferentResultsets()
+ {
+ MySqlDataReader reader =null;
+ try
+ {
+ MySqlCommand cmd = new MySqlCommand("", conn);
+ // insert 100 records
+ cmd.CommandText = "INSERT INTO Test (id,name,dt,b1) VALUES (?id, 'test','2004-12-05 12:57:00','long blob data')";
+ cmd.Parameters.Add( new MySqlParameter("?id", 1));
+ for (int i=1; i <= 100; i++)
+ {
+ cmd.Parameters[0].Value = i;
+ cmd.ExecuteNonQuery();
+ }
+
+ cmd = new MySqlCommand("SELECT id FROM Test WHERE id<?param1; "+
+ "SELECT id,name FROM Test WHERE id = -50; "+
+ "SELECT * FROM Test WHERE id >= ?param1; "+
+ "SELECT id, dt, b1 FROM Test WHERE id = -50; "+
+ "SELECT b1 FROM Test WHERE id = -50; "+
+ "SELECT id, dt, b1 FROM Test WHERE id < ?param1; "+
+ "SELECT b1 FROM Test WHERE id >= ?param1;", conn);
+
+ cmd.Parameters.Add("?param1",50);
+
+ reader = cmd.ExecuteReader();
+
+ Assert.IsNotNull( reader );
+
+ //First ResultSet, should have 49 rows.
+ //SELECT id FROM test WHERE id<?param1;
+ Assert.AreEqual( true, reader.HasRows );
+ Assert.AreEqual( 1, reader.FieldCount );
+ for (int i = 0; i < 49; i++)
+ {
+ Assert.IsTrue( reader.Read() );
+ }
+ Assert.AreEqual( false, reader.Read() );
+
+ //Second ResultSet, should have no rows.
+ //SELECT id,name FROM test WHERE id = -50;
+ Assert.IsTrue( reader.NextResult() );
+ Assert.AreEqual( false, reader.HasRows );
+ Assert.AreEqual( 2, reader.FieldCount );
+ Assert.AreEqual( false, reader.Read() );
+
+
+ //Third ResultSet, should have 51 rows.
+ //SELECT * FROM test WHERE id >= ?param1;
+ Assert.IsTrue( reader.NextResult() );
+ Assert.AreEqual( true, reader.HasRows );
+ Assert.AreEqual( 5, reader.FieldCount );
+ for (int i = 0; i < 51; i++)
+ {
+ Assert.IsTrue( reader.Read() );
+ }
+ Assert.AreEqual( false, reader.Read() );
+
+
+ //Fourth ResultSet, should have no rows.
+ //SELECT id, dt, b1 FROM test WHERE id = -50;
+ Assert.IsTrue( reader.NextResult() );
+ Assert.AreEqual( false, reader.HasRows );
+ Assert.AreEqual( 3, reader.FieldCount ); //Will Fail if uncommented expected 3 returned 5
+ Assert.AreEqual( false, reader.Read() );
+
+ //Fifth ResultSet, should have no rows.
+ //SELECT b1 FROM test WHERE id = -50;
+ Assert.IsTrue( reader.NextResult() );
+ Assert.AreEqual( false, reader.HasRows );
+ Assert.AreEqual( 1, reader.FieldCount ); //Will Fail if uncommented expected 1 returned 5
+ Assert.AreEqual( false, reader.Read() );
+
+ //Sixth ResultSet, should have 49 rows.
+ //SELECT id, dt, b1 FROM test WHERE id < ?param1;
+ Assert.IsTrue( reader.NextResult() );
+ Assert.AreEqual( true, reader.HasRows );
+ Assert.AreEqual( 3, reader.FieldCount ); //Will Fail if uncommented expected 3 returned 5
+ for (int i = 0; i < 49; i++)
+ {
+ Assert.IsTrue( reader.Read() );
+ }
+ Assert.AreEqual( false, reader.Read() );
+
+ //Seventh ResultSet, should have 51 rows.
+ //SELECT b1 FROM test WHERE id >= ?param1;
+ Assert.IsTrue( reader.NextResult() );
+ Assert.AreEqual( true, reader.HasRows );
+ Assert.AreEqual( 1, reader.FieldCount ); //Will Fail if uncommented expected 1 returned 5
+ for (int i = 0; i < 51; i++)
+ {
+ Assert.IsTrue( reader.Read() );
+ }
+ Assert.AreEqual( false, reader.Read() );
+ }
+ catch (Exception ex)
+ {
+ Assert.Fail( ex.Message );
+ }
+ finally
+ {
+ if (reader != null) reader.Close();
+ }
+ }
+
+
+ [Test]
+ public void TestMultipleResultsWithQueryCacheOn()
+ {
+ execSQL("SET SESSION query_cache_type = ON");
+ execSQL("INSERT INTO Test (id,name) VALUES (1, 'Test')");
+ execSQL("INSERT INTO Test (id,name) VALUES (51, 'Test')");
+
+
+ MySqlDataReader reader =null;
+
+ try
+ {
+
+ // execute it one time
+ MySqlCommand cmd = new MySqlCommand("SELECT id FROM Test WHERE id<50; SELECT * FROM Test WHERE id >= 50;", conn);
+
+ reader = cmd.ExecuteReader();
+
+ Assert.IsNotNull( reader );
+ Assert.AreEqual( true, reader.HasRows );
+ Assert.IsTrue( reader.Read() );
+ Assert.AreEqual( 1, reader.FieldCount );
+ Assert.IsTrue( reader.NextResult() );
+ Assert.AreEqual( true, reader.HasRows );
+ Assert.AreEqual( 5, reader.FieldCount );
+
+ reader.Close();
+
+ // now do it again
+ reader = cmd.ExecuteReader();
+ Assert.IsNotNull( reader );
+ Assert.AreEqual( true, reader.HasRows );
+ Assert.IsTrue( reader.Read() );
+ Assert.AreEqual( 1, reader.FieldCount );
+ Assert.IsTrue( reader.NextResult() );
+ Assert.AreEqual( true, reader.HasRows );
+ Assert.AreEqual( 5, reader.FieldCount );
+
+ reader.Close();
+ }
+ catch (Exception ex)
+ {
+ Assert.Fail( ex.Message );
+ }
+ finally
+ {
+ if (reader != null) reader.Close();
+ }
+ }
+
+ /// <summary>
+ /// Bug #8630 Executing a query with the SchemaOnly option reads the entire resultset
+ /// </summary>
+ [Test]
+ public void SchemaOnly()
+ {
+ execSQL("INSERT INTO Test (id,name) VALUES(1,'test1')");
+ execSQL("INSERT INTO Test (id,name) VALUES(2,'test2')");
+ execSQL("INSERT INTO Test (id,name) VALUES(3,'test3')");
+
+ MySqlCommand cmd = new MySqlCommand("SELECT * FROM test", conn);
+ MySqlDataReader reader = null;
+ try
+ {
+ reader = cmd.ExecuteReader(CommandBehavior.SchemaOnly);
+ DataTable table = reader.GetSchemaTable();
+ Assert.AreEqual(5, table.Rows.Count);
+ Assert.AreEqual(22, table.Columns.Count);
+ Assert.IsFalse(reader.Read());
+ }
+ catch (Exception ex)
+ {
+ Assert.Fail(ex.Message);
+ }
+ finally
+ {
+ if (reader != null) reader.Close();
+ }
+ }
+
+ /// <summary>
+ /// Bug #9237 MySqlDataReader.AffectedRecords not set to -1
+ /// </summary>
+ [Test]
+ public void AffectedRows()
+ {
+ MySqlCommand cmd = new MySqlCommand("SHOW TABLES", conn);
+ try
+ {
+ using (MySqlDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ reader.Close();
+ Assert.AreEqual(-1, reader.RecordsAffected);
+ }
+ }
+ catch (Exception ex)
+ {
+ Assert.Fail(ex.Message);
+ }
+ }
+
+ /// <summary>
+ /// Bug #11873 Invalid timestamp in query produces incorrect reader exception
+ /// </summary>
+ [Test]
+ public void InvalidTimestamp()
+ {
+ execSQL("DROP TABLE IF EXISTS test");
+ execSQL("CREATE TABLE test (tm TIMESTAMP)");
+ execSQL("INSERT INTO test VALUES (NULL)");
+
+ MySqlCommand cmd = new MySqlCommand("SELECT * FROM test WHERE tm = '7/1/2005 12:00:00 AM'", conn);
+ MySqlDataReader reader = null;
+ try
+ {
+ reader = cmd.ExecuteReader();
+ }
+ catch (Exception ex)
+ {
+ Assert.Fail(ex.Message);
+ }
+ finally
+ {
+ if (reader != null) reader.Close();
+ }
+ }
+
+ /// <summary>
+ /// Bug #19294 IDataRecord.GetString method should return null for null values
+ /// </summary>
+ [Test]
+ public void GetStringOnNull()
+ {
+ execSQL("DROP TABLE IF EXISTS test");
+ execSQL("CREATE TABLE test (id int, PRIMARY KEY(id))");
+ MySqlCommand cmd = new MySqlCommand("SHOW INDEX FROM test FROM test", conn);
+ MySqlDataReader reader = null;
+ try
+ {
+ reader = cmd.ExecuteReader();
+ reader.Read();
+ string s = reader.GetString(reader.GetOrdinal("Sub_part"));
+ Assert.Fail("We should not get here");
+ }
+ catch (System.Data.SqlTypes.SqlNullValueException)
+ {
+ }
+ catch (Exception ex)
+ {
+ Assert.Fail(ex.Message);
+ }
+ finally
+ {
+ if (reader != null)
+ reader.Close();
+ }
+ }
+ }
+}
Modified: trunk/TestSuite/InterfaceTests.cs
===================================================================
--- trunk/TestSuite/InterfaceTests.cs 2006-07-30 15:48:19 UTC (rev 285)
+++ trunk/TestSuite/InterfaceTests.cs 2006-07-30 16:36:21 UTC (rev 286)
@@ -1,4 +1,4 @@
-// Copyright (C) 2004 MySQL AB
+// 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
Modified: trunk/TestSuite/ParameterTests.cs
===================================================================
--- trunk/TestSuite/ParameterTests.cs 2006-07-30 15:48:19 UTC (rev 285)
+++ trunk/TestSuite/ParameterTests.cs 2006-07-30 16:36:21 UTC (rev 286)
@@ -1,367 +1,367 @@
-// 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.Data;
-using MySql.Data.MySqlClient;
-using NUnit.Framework;
-
-namespace MySql.Data.MySqlClient.Tests
-{
- /// <summary>
- /// Summary description for ConnectionTests.
- /// </summary>
- [TestFixture]
- public class ParameterTests : BaseTest
- {
- [TestFixtureSetUp]
- public void SetUp()
- {
- Open();
- }
-
- [TestFixtureTearDown]
- public void TearDown()
- {
- Close();
+// 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.Data;
+using MySql.Data.MySqlClient;
+using NUnit.Framework;
+
+namespace MySql.Data.MySqlClient.Tests
+{
+ /// <summary>
+ /// Summary description for ConnectionTests.
+ /// </summary>
+ [TestFixture]
+ public class ParameterTests : BaseTest
+ {
+ [TestFixtureSetUp]
+ public void SetUp()
+ {
+ Open();
}
+ [TestFixtureTearDown]
+ public void TearDown()
+ {
+ Close();
+ }
+
protected override void Setup()
{
base.Setup();
execSQL("DROP TABLE IF EXISTS Test");
execSQL("CREATE TABLE Test (id INT NOT NULL, name VARCHAR(100), dt DATETIME, tm TIME, ts TIMESTAMP, PRIMARY KEY(id))");
- }
-
- [Test]
- public void TestUserVariables()
- {
- MySqlCommand cmd = new MySqlCommand("SET @myvar = 'test'", conn);
- cmd.ExecuteNonQuery();
-
- cmd.CommandText = "SELECT @myvar";
- MySqlDataReader reader = cmd.ExecuteReader();
- try
- {
- Assert.AreEqual( true, reader.Read());
- Assert.AreEqual( "test", reader.GetValue(0));
- }
- catch (Exception ex)
- {
- Assert.Fail( ex.Message );
- }
- finally
- {
- reader.Close();
- }
- }
-
- [Test]
- public void TestQuoting()
- {
- MySqlCommand cmd = new MySqlCommand("", conn);
- cmd.CommandText = "INSERT INTO Test VALUES (?id, ?name, NULL,NULL,NULL)";
- cmd.Parameters.Add( new MySqlParameter("?id", 1));
- cmd.Parameters.Add( new MySqlParameter("?name", "my ' value"));
- cmd.ExecuteNonQuery();
-
- cmd.Parameters[0].Value = 2;
- cmd.Parameters[1].Value = @"my "" value";
- cmd.ExecuteNonQuery();
-
- cmd.Parameters[0].Value = 3;
- cmd.Parameters[1].Value = @"my ` value";
- cmd.ExecuteNonQuery();
-
- cmd.Parameters[0].Value = 4;
- cmd.Parameters[1].Value = @"my - cmd.ExecuteNonQuery();
-
- cmd.Parameters[0].Value = 5;
- cmd.Parameters[1].Value = @"my \ value";
- cmd.ExecuteNonQuery();
-
- cmd.CommandText = "SELECT * FROM Test";
- MySqlDataReader reader = null;
- try
- {
- reader = cmd.ExecuteReader();
- reader.Read();
- Assert.AreEqual( "my ' value", reader.GetString(1));
- reader.Read();
- Assert.AreEqual( @"my "" value", reader.GetString(1));
- reader.Read();
- Assert.AreEqual( "my ` value", reader.GetString(1));
- reader.Read();
- Assert.AreEqual( "my - reader.Read();
- Assert.AreEqual( @"my \ value", reader.GetString(1));
- }
- catch (Exception ex)
- {
- Assert.Fail( ex.Message );
- }
- finally
- {
- if (reader != null) reader.Close();
- }
- }
-
- [Test]
- public void TestDateTimeParameter()
- {
- MySqlCommand cmd = new MySqlCommand("", conn);
-
- TimeSpan time = new TimeSpan(0, 1, 2, 3);
- DateTime dt = new DateTime( 2003, 11, 11, 1, 2, 3 );
- cmd.CommandText = "INSERT INTO Test VALUES (1, 'test', ?dt, ?time, NULL)";
- cmd.Parameters.Add( new MySqlParameter("?time", time));
- cmd.Parameters.Add( new MySqlParameter("?dt", dt));
- int cnt = cmd.ExecuteNonQuery();
- Assert.AreEqual( 1, cnt, "Insert count" );
-
- cmd = new MySqlCommand("SELECT tm, dt, ts FROM Test WHERE id=1", conn);
- MySqlDataReader reader = cmd.ExecuteReader();
- reader.Read();
- TimeSpan time2 = (TimeSpan)reader.GetValue(0);
- Assert.AreEqual( time, time2 );
-
- DateTime dt2 = reader.GetDateTime(1);
- Assert.AreEqual( dt, dt2 );
-
- DateTime ts2 = reader.GetDateTime(2);
- reader.Close();
-
- // now check the timestamp column. We won't check the minute or second for obvious reasons
- DateTime now = DateTime.Now;
- Assert.AreEqual( now.Year, ts2.Year );
- Assert.AreEqual( now.Month, ts2.Month );
- Assert.AreEqual( now.Day, ts2.Day );
- Assert.AreEqual( now.Hour, ts2.Hour );
-
- // now we'll set some nulls and see how they are handled
- cmd = new MySqlCommand("UPDATE Test SET tm=?ts, dt=?dt WHERE id=1", conn);
- cmd.Parameters.Add( new MySqlParameter("?ts", DBNull.Value ));
- cmd.Parameters.Add( new MySqlParameter("?dt", DBNull.Value));
- cnt = cmd.ExecuteNonQuery();
- Assert.AreEqual( 1, cnt, "Update null count" );
-
- cmd = new MySqlCommand("SELECT tm, dt FROM Test WHERE id=1", conn);
- reader = cmd.ExecuteReader();
- reader.Read();
- object tso = reader.GetValue(0);
- object dto = reader.GetValue(1);
- Assert.AreEqual( DBNull.Value, tso, "Time column" );
- Assert.AreEqual( DBNull.Value, dto, "DateTime column" );
-
- reader.Close();
-
- cmd.CommandText = "DELETE FROM Test WHERE id=1";
- cmd.ExecuteNonQuery();
- }
-
- [Test]
- public void NestedQuoting()
- {
- MySqlCommand cmd = new MySqlCommand("INSERT INTO Test (id, name) " +
- "VALUES(1, 'this is ?\"my value\"')", conn);
- int count = cmd.ExecuteNonQuery();
- Assert.AreEqual(1, count);
- }
-
- [Test]
- public void SetDbType()
- {
- try
- {
- IDbConnection conn2 = (IDbConnection)conn;
- IDbCommand cmd = conn.CreateCommand();
- IDbDataParameter prm = cmd.CreateParameter();
- prm.DbType = DbType.Int64;
- Assert.AreEqual(DbType.Int64, prm.DbType);
- prm.Value = 3;
- Assert.AreEqual(DbType.Int64, prm.DbType);
-
- MySqlParameter p = new MySqlParameter("name", MySqlDbType.Int64);
- Assert.AreEqual(DbType.Int64, p.DbType);
- Assert.AreEqual(MySqlDbType.Int64, p.MySqlDbType);
- p.Value = 3;
- Assert.AreEqual(DbType.Int64, p.DbType);
- Assert.AreEqual(MySqlDbType.Int64, p.MySqlDbType);
- }
- catch (Exception ex)
- {
- Assert.Fail(ex.Message);
- }
- }
-
- [Test]
- public void UseOldSyntax()
- {
- string connStr = conn.ConnectionString + ";old syntax=yes;pooling=false";
- MySqlConnection conn2 = new MySqlConnection(connStr);
- conn2.Open();
-
- MySqlCommand cmd = new MySqlCommand("INSERT INTO Test (id, name) VALUES (@id, @name)", conn2);
- cmd.Parameters.Add( "@id", 33 );
- cmd.Parameters.Add( "@name", "Test" );
- cmd.ExecuteNonQuery();
-
- MySqlDataReader reader = null;
- try
- {
- cmd.CommandText = "SELECT * FROM Test";
- reader = cmd.ExecuteReader();
- reader.Read();
- Assert.AreEqual( 33, reader.GetInt32(0) );
- Assert.AreEqual( "Test", reader.GetString(1) );
- }
- catch( Exception ex)
- {
- Assert.Fail( ex.Message );
- }
- finally
- {
- if (reader != null) reader.Close();
- conn2.Close();
- }
- }
-
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void NullParameterObject()
- {
- MySqlCommand cmd = new MySqlCommand("INSERT INTO Test (id, name) VALUES (1, ?name)", conn);
- cmd.Parameters.Add( null );
- }
-
- /// <summary>
- /// Bug #7398 MySqlParameterCollection doesn't allow parameters without filled in names
- /// </summary>
- [Test]
- public void AllowUnnamedParameters()
- {
- MySqlCommand cmd = new MySqlCommand("INSERT INTO test (id,name) VALUES (?id, ?name)", conn);
-
- MySqlParameter p = new MySqlParameter();
- p.ParameterName = "?id";
- p.Value = 1;
- cmd.Parameters.Add(p);
-
- p = new MySqlParameter();
- p.ParameterName = "?name";
- p.Value = "test";
- cmd.Parameters.Add(p);
-
- cmd.ExecuteNonQuery();
-
- cmd.CommandText = "SELECT id FROM test";
- Assert.AreEqual(1, cmd.ExecuteScalar());
-
- cmd.CommandText = "SELECT name FROM test";
- Assert.AreEqual( "test", cmd.ExecuteScalar());
- }
-
- [Test]
- public void NullParameterValue()
- {
- MySqlCommand cmd = new MySqlCommand("INSERT INTO Test (id, name) VALUES (1, ?name)", conn);
- cmd.Parameters.Add( new MySqlParameter("?name", null));
- cmd.ExecuteNonQuery();
-
- cmd.CommandText = "SELECT name FROM Test WHERE id=1";
- object name = cmd.ExecuteScalar();
- Assert.AreEqual( DBNull.Value, name );
- }
-
- /// <summary>
- /// Bug #12646 Parameters are defaulted to Decimal
- /// </summary>
- [Test]
- public void DefaultType()
- {
- IDbCommand cmd = conn.CreateCommand();
- IDbDataParameter p = cmd.CreateParameter();
- p.ParameterName = "?boo";
- p.Value = "test";
- MySqlParameter mp = (MySqlParameter)p;
- Assert.AreEqual(MySqlDbType.VarChar, mp.MySqlDbType);
- }
-
- [Test]
- public void OddCharsInParameterNames()
- {
- MySqlCommand cmd = new MySqlCommand("INSERT INTO Test (id, name) VALUES (1, ?nam$es)", conn);
- cmd.Parameters.Add( new MySqlParameter("?nam$es", "Test"));
- cmd.ExecuteNonQuery();
-
- cmd.CommandText = "INSERT INTO Test (id, name) VALUES (2, ?nam_es)";
- cmd.Parameters.Clear();
- cmd.Parameters.Add( new MySqlParameter("?nam_es", "Test2"));
- cmd.ExecuteNonQuery();
-
- cmd.CommandText = "INSERT INTO Test (id, name) VALUES (3, ?nam.es)";
- cmd.Parameters.Clear();
- cmd.Parameters.Add( new MySqlParameter("?nam.es", "Test3"));
- cmd.ExecuteNonQuery();
-
- cmd.CommandText = "SELECT name FROM Test WHERE id=1";
- object name = cmd.ExecuteScalar();
- Assert.AreEqual( "Test", name );
-
- cmd.CommandText = "SELECT name FROM Test WHERE id=2";
- name = cmd.ExecuteScalar();
- Assert.AreEqual( "Test2", name );
-
- cmd.CommandText = "SELECT name FROM Test WHERE id=3";
- name = cmd.ExecuteScalar();
- Assert.AreEqual( "Test3", name );
- }
-
- /// <summary>
- /// Bug #13276 Exception on serialize after inserting null value
- /// </summary>
- [Test]
- public void InsertValueAfterNull()
- {
- execSQL("DROP TABLE IF EXISTS test");
- execSQL("CREATE TABLE test (id int auto_increment primary key, foo int)");
-
- MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM test", conn);
- MySqlCommand c = new MySqlCommand("INSERT INTO test (foo) values (?foo)", conn);
- c.Parameters.Add("foo", MySqlDbType.Int32, 0, "foo");
-
- da.InsertCommand = c;
- DataTable dt = new DataTable();
- da.Fill(dt);
- DataRow row = dt.NewRow();
- dt.Rows.Add(row);
- row = dt.NewRow();
- row["foo"] = 2;
- dt.Rows.Add(row);
- da.Update(dt);
-
- dt.Clear();
- da.Fill(dt);
- Assert.AreEqual(2, dt.Rows.Count);
- Assert.AreEqual(2, dt.Rows[1]["foo"]);
- }
- }
-}
+ }
+
+ [Test]
+ public void TestUserVariables()
+ {
+ MySqlCommand cmd = new MySqlCommand("SET @myvar = 'test'", conn);
+ cmd.ExecuteNonQuery();
+
+ cmd.CommandText = "SELECT @myvar";
+ MySqlDataReader reader = cmd.ExecuteReader();
+ try
+ {
+ Assert.AreEqual( true, reader.Read());
+ Assert.AreEqual( "test", reader.GetValue(0));
+ }
+ catch (Exception ex)
+ {
+ Assert.Fail( ex.Message );
+ }
+ finally
+ {
+ reader.Close();
+ }
+ }
+
+ [Test]
+ public void TestQuoting()
+ {
+ MySqlCommand cmd = new MySqlCommand("", conn);
+ cmd.CommandText = "INSERT INTO Test VALUES (?id, ?name, NULL,NULL,NULL)";
+ cmd.Parameters.Add( new MySqlParameter("?id", 1));
+ cmd.Parameters.Add( new MySqlParameter("?name", "my ' value"));
+ cmd.ExecuteNonQuery();
+
+ cmd.Parameters[0].Value = 2;
+ cmd.Parameters[1].Value = @"my "" value";
+ cmd.ExecuteNonQuery();
+
+ cmd.Parameters[0].Value = 3;
+ cmd.Parameters[1].Value = @"my ` value";
+ cmd.ExecuteNonQuery();
+
+ cmd.Parameters[0].Value = 4;
+ cmd.Parameters[1].Value = @"my + cmd.ExecuteNonQuery();
+
+ cmd.Parameters[0].Value = 5;
+ cmd.Parameters[1].Value = @"my \ value";
+ cmd.ExecuteNonQuery();
+
+ cmd.CommandText = "SELECT * FROM Test";
+ MySqlDataReader reader = null;
+ try
+ {
+ reader = cmd.ExecuteReader();
+ reader.Read();
+ Assert.AreEqual( "my ' value", reader.GetString(1));
+ reader.Read();
+ Assert.AreEqual( @"my "" value", reader.GetString(1));
+ reader.Read();
+ Assert.AreEqual( "my ` value", reader.GetString(1));
+ reader.Read();
+ Assert.AreEqual( "my + reader.Read();
+ Assert.AreEqual( @"my \ value", reader.GetString(1));
+ }
+ catch (Exception ex)
+ {
+ Assert.Fail( ex.Message );
+ }
+ finally
+ {
+ if (reader != null) reader.Close();
+ }
+ }
+
+ [Test]
+ public void TestDateTimeParameter()
+ {
+ MySqlCommand cmd = new MySqlCommand("", conn);
+
+ TimeSpan time = new TimeSpan(0, 1, 2, 3);
+ DateTime dt = new DateTime( 2003, 11, 11, 1, 2, 3 );
+ cmd.CommandText = "INSERT INTO Test VALUES (1, 'test', ?dt, ?time, NULL)";
+ cmd.Parameters.Add( new MySqlParameter("?time", time));
+ cmd.Parameters.Add( new MySqlParameter("?dt", dt));
+ int cnt = cmd.ExecuteNonQuery();
+ Assert.AreEqual( 1, cnt, "Insert count" );
+
+ cmd = new MySqlCommand("SELECT tm, dt, ts FROM Test WHERE id=1", conn);
+ MySqlDataReader reader = cmd.ExecuteReader();
+ reader.Read();
+ TimeSpan time2 = (TimeSpan)reader.GetValue(0);
+ Assert.AreEqual( time, time2 );
+
+ DateTime dt2 = reader.GetDateTime(1);
+ Assert.AreEqual( dt, dt2 );
+
+ DateTime ts2 = reader.GetDateTime(2);
+ reader.Close();
+
+ // now check the timestamp column. We won't check the minute or second for obvious reasons
+ DateTime now = DateTime.Now;
+ Assert.AreEqual( now.Year, ts2.Year );
+ Assert.AreEqual( now.Month, ts2.Month );
+ Assert.AreEqual( now.Day, ts2.Day );
+ Assert.AreEqual( now.Hour, ts2.Hour );
+
+ // now we'll set some nulls and see how they are handled
+ cmd = new MySqlCommand("UPDATE Test SET tm=?ts, dt=?dt WHERE id=1", conn);
+ cmd.Parameters.Add( new MySqlParameter("?ts", DBNull.Value ));
+ cmd.Parameters.Add( new MySqlParameter("?dt", DBNull.Value));
+ cnt = cmd.ExecuteNonQuery();
+ Assert.AreEqual( 1, cnt, "Update null count" );
+
+ cmd = new MySqlCommand("SELECT tm, dt FROM Test WHERE id=1", conn);
+ reader = cmd.ExecuteReader();
+ reader.Read();
+ object tso = reader.GetValue(0);
+ object dto = reader.GetValue(1);
+ Assert.AreEqual( DBNull.Value, tso, "Time column" );
+ Assert.AreEqual( DBNull.Value, dto, "DateTime column" );
+
+ reader.Close();
+
+ cmd.CommandText = "DELETE FROM Test WHERE id=1";
+ cmd.ExecuteNonQuery();
+ }
+
+ [Test]
+ public void NestedQuoting()
+ {
+ MySqlCommand cmd = new MySqlCommand("INSERT INTO Test (id, name) " +
+ "VALUES(1, 'this is ?\"my value\"')", conn);
+ int count = cmd.ExecuteNonQuery();
+ Assert.AreEqual(1, count);
+ }
+
+ [Test]
+ public void SetDbType()
+ {
+ try
+ {
+ IDbConnection conn2 = (IDbConnection)conn;
+ IDbCommand cmd = conn.CreateCommand();
+ IDbDataParameter prm = cmd.CreateParameter();
+ prm.DbType = DbType.Int64;
+ Assert.AreEqual(DbType.Int64, prm.DbType);
+ prm.Value = 3;
+ Assert.AreEqual(DbType.Int64, prm.DbType);
+
+ MySqlParameter p = new MySqlParameter("name", MySqlDbType.Int64);
+ Assert.AreEqual(DbType.Int64, p.DbType);
+ Assert.AreEqual(MySqlDbType.Int64, p.MySqlDbType);
+ p.Value = 3;
+ Assert.AreEqual(DbType.Int64, p.DbType);
+ Assert.AreEqual(MySqlDbType.Int64, p.MySqlDbType);
+ }
+ catch (Exception ex)
+ {
+ Assert.Fail(ex.Message);
+ }
+ }
+
+ [Test]
+ public void UseOldSyntax()
+ {
+ string connStr = conn.ConnectionString + ";old syntax=yes;pooling=false";
+ MySqlConnection conn2 = new MySqlConnection(connStr);
+ conn2.Open();
+
+ MySqlCommand cmd = new MySqlCommand("INSERT INTO Test (id, name) VALUES (@id, @name)", conn2);
+ cmd.Parameters.Add( "@id", 33 );
+ cmd.Parameters.Add( "@name", "Test" );
+ cmd.ExecuteNonQuery();
+
+ MySqlDataReader reader = null;
+ try
+ {
+ cmd.CommandText = "SELECT * FROM Test";
+ reader = cmd.ExecuteReader();
+ reader.Read();
+ Assert.AreEqual( 33, reader.GetInt32(0) );
+ Assert.AreEqual( "Test", reader.GetString(1) );
+ }
+ catch( Exception ex)
+ {
+ Assert.Fail( ex.Message );
+ }
+ finally
+ {
+ if (reader != null) reader.Close();
+ conn2.Close();
+ }
+ }
+
+ [Test]
+ [ExpectedException(typeof(ArgumentException))]
+ public void NullParameterObject()
+ {
+ MySqlCommand cmd = new MySqlCommand("INSERT INTO Test (id, name) VALUES (1, ?name)", conn);
+ cmd.Parameters.Add( null );
+ }
+
+ /// <summary>
+ /// Bug #7398 MySqlParameterCollection doesn't allow parameters without filled in names
+ /// </summary>
+ [Test]
+ public void AllowUnnamedParameters()
+ {
+ MySqlCommand cmd = new MySqlCommand("INSERT INTO test (id,name) VALUES (?id, ?name)", conn);
+
+ MySqlParameter p = new MySqlParameter();
+ p.ParameterName = "?id";
+ p.Value = 1;
+ cmd.Parameters.Add(p);
+
+ p = new MySqlParameter();
+ p.ParameterName = "?name";
+ p.Value = "test";
+ cmd.Parameters.Add(p);
+
+ cmd.ExecuteNonQuery();
+
+ cmd.CommandText = "SELECT id FROM test";
+ Assert.AreEqual(1, cmd.ExecuteScalar());
+
+ cmd.CommandText = "SELECT name FROM test";
+ Assert.AreEqual( "test", cmd.ExecuteScalar());
+ }
+
+ [Test]
+ public void NullParameterValue()
+ {
+ MySqlCommand cmd = new MySqlCommand("INSERT INTO Test (id, name) VALUES (1, ?name)", conn);
+ cmd.Parameters.Add( new MySqlParameter("?name", null));
+ cmd.ExecuteNonQuery();
+
+ cmd.CommandText = "SELECT name FROM Test WHERE id=1";
+ object name = cmd.ExecuteScalar();
+ Assert.AreEqual( DBNull.Value, name );
+ }
+
+ /// <summary>
+ /// Bug #12646 Parameters are defaulted to Decimal
+ /// </summary>
+ [Test]
+ public void DefaultType()
+ {
+ IDbCommand cmd = conn.CreateCommand();
+ IDbDataParameter p = cmd.CreateParameter();
+ p.ParameterName = "?boo";
+ p.Value = "test";
+ MySqlParameter mp = (MySqlParameter)p;
+ Assert.AreEqual(MySqlDbType.VarChar, mp.MySqlDbType);
+ }
+
+ [Test]
+ public void OddCharsInParameterNames()
+ {
+ MySqlCommand cmd = new MySqlCommand("INSERT INTO Test (id, name) VALUES (1, ?nam$es)", conn);
+ cmd.Parameters.Add( new MySqlParameter("?nam$es", "Test"));
+ cmd.ExecuteNonQuery();
+
+ cmd.CommandText = "INSERT INTO Test (id, name) VALUES (2, ?nam_es)";
+ cmd.Parameters.Clear();
+ cmd.Parameters.Add( new MySqlParameter("?nam_es", "Test2"));
+ cmd.ExecuteNonQuery();
+
+ cmd.CommandText = "INSERT INTO Test (id, name) VALUES (3, ?nam.es)";
+ cmd.Parameters.Clear();
+ cmd.Parameters.Add( new MySqlParameter("?nam.es", "Test3"));
+ cmd.ExecuteNonQuery();
+
+ cmd.CommandText = "SELECT name FROM Test WHERE id=1";
+ object name = cmd.ExecuteScalar();
+ Assert.AreEqual( "Test", name );
+
+ cmd.CommandText = "SELECT name FROM Test WHERE id=2";
+ name = cmd.ExecuteScalar();
+ Assert.AreEqual( "Test2", name );
+
+ cmd.CommandText = "SELECT name FROM Test WHERE id=3";
+ name = cmd.ExecuteScalar();
+ Assert.AreEqual( "Test3", name );
+ }
+
+ /// <summary>
+ /// Bug #13276 Exception on serialize after inserting null value
+ /// </summary>
+ [Test]
+ public void InsertValueAfterNull()
+ {
+ execSQL("DROP TABLE IF EXISTS test");
+ execSQL("CREATE TABLE test (id int auto_increment primary key, foo int)");
+
+ MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM test", conn);
+ MySqlCommand c = new MySqlCommand("INSERT INTO test (foo) values (?foo)", conn);
+ c.Parameters.Add("foo", MySqlDbType.Int32, 0, "foo");
+
+ da.InsertCommand = c;
+ DataTable dt = new DataTable();
+ da.Fill(dt);
+ DataRow row = dt.NewRow();
+ dt.Rows.Add(row);
+ row = dt.NewRow();
+ row["foo"] = 2;
+ dt.Rows.Add(row);
+ da.Update(dt);
+
+ dt.Clear();
+ da.Fill(dt);
+ Assert.AreEqual(2, dt.Rows.Count);
+ Assert.AreEqual(2, dt.Rows[1]["foo"]);
+ }
+ }
+}
Modified: trunk/TestSuite/PerfMonTests.cs
===================================================================
--- trunk/TestSuite/PerfMonTests.cs 2006-07-30 15:48:19 UTC (rev 285)
+++ trunk/TestSuite/PerfMonTests.cs 2006-07-30 16:36:21 UTC (rev 286)
@@ -1,4 +1,4 @@
-// Copyright (C) 2004-2005 MySQL AB
+// 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
@@ -17,6 +17,7 @@
// 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.Data;
using MySql.Data.MySqlClient;
Modified: trunk/TestSuite/SchemaTests.cs
===================================================================
--- trunk/TestSuite/SchemaTests.cs 2006-07-30 15:48:19 UTC (rev 285)
+++ trunk/TestSuite/SchemaTests.cs 2006-07-30 16:36:21 UTC (rev 286)
@@ -1,4 +1,4 @@
-// Copyright (C) 2004-2005 MySQL AB
+// 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
@@ -17,6 +17,7 @@
// 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.Data;
using MySql.Data.MySqlClient;
Modified: trunk/TestSuite/StoredProcedure.cs
===================================================================
--- trunk/TestSuite/StoredProcedure.cs 2006-07-30 15:48:19 UTC (rev 285)
+++ trunk/TestSuite/StoredProcedure.cs 2006-07-30 16:36:21 UTC (rev 286)
@@ -17,6 +17,7 @@
// 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.Data;
using MySql.Data.MySqlClient;
Modified: trunk/TestSuite/Syntax.cs
===================================================================
--- trunk/TestSuite/Syntax.cs 2006-07-30 15:48:19 UTC (rev 285)
+++ trunk/TestSuite/Syntax.cs 2006-07-30 16:36:21 UTC (rev 286)
@@ -1,4 +1,4 @@
-// Copyright (C) 2004-2005 MySQL AB
+// 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
Modified: trunk/TestSuite/UsageAdvisor.cs
===================================================================
--- trunk/TestSuite/UsageAdvisor.cs 2006-07-30 15:48:19 UTC (rev 285)
+++ trunk/TestSuite/UsageAdvisor.cs 2006-07-30 16:36:21 UTC (rev 286)
@@ -1,4 +1,4 @@
-// Copyright (C) 2004 MySQL AB
+// 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
Modified: trunk/mysqlclient/MySql.Data.2005.csproj
===================================================================
--- trunk/mysqlclient/MySql.Data.2005.csproj 2006-07-30 15:48:19 UTC (rev 285)
+++ trunk/mysqlclient/MySql.Data.2005.csproj 2006-07-30 16:36:21 UTC (rev 286)
@@ -169,7 +169,6 @@
<Compile Include="Types\MySqlUInt32.cs" />
<Compile Include="Types\MySqlUInt64.cs" />
<Compile Include="Types\MySqlValue.cs" />
- <Compile Include="Types\NumberFormat.cs" />
<Compile Include="UsageAdvisor.cs" />
</ItemGroup>
<ItemGroup>
Modified: trunk/mysqlclient/Types/MetaData.cs
===================================================================
--- trunk/mysqlclient/Types/MetaData.cs 2006-07-30 15:48:19 UTC (rev 285)
+++ trunk/mysqlclient/Types/MetaData.cs 2006-07-30 16:36:21 UTC (rev 286)
@@ -1,3 +1,23 @@
+// 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 MySql.Data.MySqlClient;
using System.Globalization;
Modified: trunk/mysqlclient/Types/MySqlBinary.cs
===================================================================
--- trunk/mysqlclient/Types/MySqlBinary.cs 2006-07-30 15:48:19 UTC (rev 285)
+++ trunk/mysqlclient/Types/MySqlBinary.cs 2006-07-30 16:36:21 UTC (rev 286)
@@ -1,361 +1,361 @@
-// 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.Data;
-using MySql.Data.MySqlClient;
-
-namespace MySql.Data.Types
-{
-
- internal struct MySqlBinary : IMySqlValue
- {
- private MySqlDbType type;
- private byte[] mValue;
- private bool isNull;
-
- public MySqlBinary(MySqlDbType type, bool isNull)
- {
- this.type = type;
- this.isNull = isNull;
- mValue = null;
- }
-
- public MySqlBinary(MySqlDbType type, byte[] val)
- {
- this.type = type;
- this.isNull = false;
- mValue = val;
- }
-
- #region IMySqlValue Members
-
- public bool IsNull
- {
- get { return isNull; }
- }
-
- public MySql.Data.MySqlClient.MySqlDbType MySqlDbType
- {
- get { return type; }
- }
-
- public System.Data.DbType DbType
- {
- get { return DbType.Binary; }
- }
-
- object IMySqlValue.Value
- {
- get { return mValue; }
- }
-
- public byte[] Value
- {
- get { return mValue; }
- }
-
- public Type SystemType
- {
- get { return typeof(byte[]); }
- }
-
- public string MySqlTypeName
- {
- get
- {
- switch (type)
- {
- case MySqlDbType.TinyBlob: return "TINY_BLOB";
- case MySqlDbType.MediumBlob: return "MEDIUM_BLOB";
- case MySqlDbType.LongBlob: return "LONG_BLOB";
- case MySqlDbType.Blob:
- default:
- return "BLOB";
- }
- }
- }
-
- void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
- {
- byte[] buffToWrite = null;
-
- if (val is System.Byte[])
- buffToWrite = (byte[])val;
- else if (val is String)
+// 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.Data;
+using MySql.Data.MySqlClient;
+
+namespace MySql.Data.Types
+{
+
+ internal struct MySqlBinary : IMySqlValue
+ {
+ private MySqlDbType type;
+ private byte[] mValue;
+ private bool isNull;
+
+ public MySqlBinary(MySqlDbType type, bool isNull)
+ {
+ this.type = type;
+ this.isNull = isNull;
+ mValue = null;
+ }
+
+ public MySqlBinary(MySqlDbType type, byte[] val)
+ {
+ this.type = type;
+ this.isNull = false;
+ mValue = val;
+ }
+
+ #region IMySqlValue Members
+
+ public bool IsNull
+ {
+ get { return isNull; }
+ }
+
+ public MySql.Data.MySqlClient.MySqlDbType MySqlDbType
+ {
+ get { return type; }
+ }
+
+ public System.Data.DbType DbType
+ {
+ get { return DbType.Binary; }
+ }
+
+ object IMySqlValue.Value
+ {
+ get { return mValue; }
+ }
+
+ public byte[] Value
+ {
+ get { return mValue; }
+ }
+
+ public Type SystemType
+ {
+ get { return typeof(byte[]); }
+ }
+
+ public string MySqlTypeName
+ {
+ get
+ {
+ switch (type)
+ {
+ case MySqlDbType.TinyBlob: return "TINY_BLOB";
+ case MySqlDbType.MediumBlob: return "MEDIUM_BLOB";
+ case MySqlDbType.LongBlob: return "LONG_BLOB";
+ case MySqlDbType.Blob:
+ default:
+ return "BLOB";
+ }
+ }
+ }
+
+ void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
+ {
+ byte[] buffToWrite = null;
+
+ if (val is System.Byte[])
+ buffToWrite = (byte[])val;
+ else if (val is String)
{
string s = (val as string);
if (length == 0)
- length = s.Length;
- else
- s = s.Substring(0, length);
- buffToWrite = stream.Encoding.GetBytes(s);
- }
- else if (val is Char[])
- buffToWrite = stream.Encoding.GetBytes(val as char[]);
-
- // we assume zero length means write all of the value
+ length = s.Length;
+ else
+ s = s.Substring(0, length);
+ buffToWrite = stream.Encoding.GetBytes(s);
+ }
+ else if (val is Char[])
+ buffToWrite = stream.Encoding.GetBytes(val as char[]);
+
+ // we assume zero length means write all of the value
if (length == 0)
- length = buffToWrite.Length;
-
- if (buffToWrite == null)
- throw new MySqlException("Only byte arrays and strings can be serialized by MySqlBinary");
-
- if (binary)
- {
- stream.WriteLength(length);
- stream.Write(buffToWrite, 0, length);
- }
- else
- {
- if (stream.Version.isAtLeast(4,1,0))
- stream.WriteStringNoNull("_binary ");
-
- stream.WriteByte((byte)'\'');
- EscapeByteArray(buffToWrite, length, stream);
- stream.WriteByte((byte)'\'');
- }
- }
-
- private void EscapeByteArray(byte[] bytes, int length, MySqlStream stream)
- {
- // System.IO.MemoryStream ms = (System.IO.MemoryStream)stream.Stream;
- // ms.Capacity += (length * 2);
-
- for (int x=0; x < length; x++)
- {
- byte b = bytes[x];
- if (b == '\0')
- {
- stream.WriteByte( (byte)'\\' );
- stream.WriteByte( (byte)'0' );
- }
-
- else if (b == '\\' || b == '\'' || b == '\"')
- {
- stream.WriteByte( (byte)'\\' );
- stream.WriteByte( b );
- }
- else
- stream.WriteByte( b );
- }
- }
-
- IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
- {
- if (nullVal)
- return new MySqlBinary(type, true);
-
- if (length == -1)
- length = (long)stream.ReadFieldLength();
-
- byte[] newBuff = new byte[length];
- stream.Read(newBuff, 0, (int)length);
- return new MySqlBinary(type, newBuff);
- }
-
- void IMySqlValue.SkipValue(MySqlStream stream)
- {
- long len = stream.ReadFieldLength();
- stream.SkipBytes((int)len);
- }
-
- #endregion
-
- public static void SetDSInfo(DataTable dsTable)
- {
- string[] types = new string[] { "BLOB", "TINYBLOB", "MEDIUMBLOB", "LONGBLOB" };
- MySqlDbType[] dbtype = new MySqlDbType[] { MySqlDbType.Blob,
- MySqlDbType.TinyBlob, MySqlDbType.MediumBlob, MySqlDbType.LongBlob };
-
- // we use name indexing because this method will only be called
- // when GetSchema is called for the DataSourceInformation
- // collection and then it wil be cached.
- for (int x=0; x < types.Length; x++)
- {
- DataRow row = dsTable.NewRow();
- row["TypeName"] = types[x];
- row["ProviderDbType"] = dbtype[x];
- row["ColumnSize"] = 0;
- row["CreateFormat"] = types[x];
- row["CreateParameters"] = null;
- row["DataType"] = "Byte";
- row["IsAutoincrementable"] = false;
- row["IsBestMatch"] = true;
- row["IsCaseSensitive"] = false;
- row["IsFixedLength"] = false;
- row["IsFixedPrecisionScale"] = true;
- row["IsLong"] = true;
- row["IsNullable"] = true;
- row["IsSearchable"] = true;
- row["IsSearchableWithLike"] = true;
- row["IsUnsigned"] = false;
- row["MaximumScale"] = 0;
- row["MinimumScale"] = 0;
- row["IsConcurrencyType"] = DBNull.Value;
- row["IsLiteralsSupported"] = false;
- row["LiteralPrefix"] = null;
- row["LiteralSuffix"] = null;
- row["NativeDataType"] = null;
- dsTable.Rows.Add(row);
- }
- }
-
- }
-/*
- /// <summary>
- /// Summary description for MySqlBinary
- /// </summary>
- internal class MySqlBinary : MySqlValue
- {
- private byte[] mValue;
- private bool isBinary;
-
- public MySqlBinary(byte[] val, MySqlDbType type)
- {
- Value = val;
- mySqlDbType = type;
- }
-
- internal string ToString( System.Text.Encoding encoding )
- {
- return encoding.GetString( (byte[])mValue );
- }
-
- internal override void Serialize(PacketWriter writer, bool binary, object ourValue, int length)
- {
- byte[] buffToWrite = null;
-
- if (ourValue is System.Byte[])
- buffToWrite = (byte[])ourValue;
- else if (ourValue is String)
- {
- string s = (ourValue as string).Substring(0, length);
- buffToWrite = stream.Encoding.GetBytes(s);
- length = buffToWrite.Length;
- }
- else if (ourValue is Char[])
- {
- buffToWrite = stream.Encoding.GetBytes( (ourValue as char[]) );
- length = buffToWrite.Length;
- }
-
- if ( buffToWrite == null )
- throw new MySqlException( "Only byte arrays and strings can be serialized by MySqlBinary" );
-
- if (binary)
- {
- stream.WriteLength( length );
- stream.Write( buffToWrite, 0, length );
- }
- else
- {
- if ( stream.Version.isAtLeast(4,1,0))
- stream.WriteStringNoNull( "_binary " );
-
- stream.WriteByte( (byte)'\'');
- EscapeByteArray( buffToWrite, length, writer );
- stream.WriteByte((byte)'\'');
- }
- }
-
- public bool IsBinary
- {
- get { return isBinary; }
- set { isBinary = value; }
- }
-
- public byte[] Value
- {
- get { return mValue; }
- set { mValue = value; objectValue = value; }
- }
-
- private void EscapeByteArray( byte[] bytes, int length, PacketWriter writer )
- {
- System.IO.MemoryStream ms = (System.IO.MemoryStream)stream.Stream;
- ms.Capacity += (length * 2);
-
- for (int x=0; x < length; x++)
- {
- byte b = bytes[x];
- if (b == '\0')
- {
- stream.WriteByte( (byte)'\\' );
- stream.WriteByte( (byte)'0' );
- }
-
- else if (b == '\\' || b == '\'' || b == '\"')
- {
- stream.WriteByte( (byte)'\\' );
- stream.WriteByte( b );
- }
- else
- stream.WriteByte( b );
- }
- }
-
-
- internal override DbType DbType
- {
- get
- {
- if (isBinary) return DbType.Binary;
- return DbType.String;
- }
- }
-
-
- internal override Type SystemType
- {
- get { return typeof(byte[]); }
- }
-
- internal override string GetMySqlTypeName()
- {
- switch (mySqlDbType)
- {
- case MySqlDbType.TinyBlob: return "TINY_BLOB";
- case MySqlDbType.MediumBlob: return "MEDIUM_BLOB";
- case MySqlDbType.LongBlob: return "LONG_BLOB";
- case MySqlDbType.Blob:
- default:
- return "BLOB";
- }
- }
-
- internal override MySqlValue ReadValue(PacketReader reader, long length)
- {
- if (length == -1)
- length = (long)stream.GetFieldLength();
-
- byte[] newBuff = new byte[length];
- stream.Read( ref newBuff, 0, length );
- return new MySqlBinary( newBuff, mySqlDbType );
- }
-
- internal override void Skip(PacketReader reader)
- {
- long len = stream.GetFieldLength();
- stream.Skip( len );
- }
-
- }*/
-}
+ length = buffToWrite.Length;
+
+ if (buffToWrite == null)
+ throw new MySqlException("Only byte arrays and strings can be serialized by MySqlBinary");
+
+ if (binary)
+ {
+ stream.WriteLength(length);
+ stream.Write(buffToWrite, 0, length);
+ }
+ else
+ {
+ if (stream.Version.isAtLeast(4,1,0))
+ stream.WriteStringNoNull("_binary ");
+
+ stream.WriteByte((byte)'\'');
+ EscapeByteArray(buffToWrite, length, stream);
+ stream.WriteByte((byte)'\'');
+ }
+ }
+
+ private void EscapeByteArray(byte[] bytes, int length, MySqlStream stream)
+ {
+ // System.IO.MemoryStream ms = (System.IO.MemoryStream)stream.Stream;
+ // ms.Capacity += (length * 2);
+
+ for (int x=0; x < length; x++)
+ {
+ byte b = bytes[x];
+ if (b == '\0')
+ {
+ stream.WriteByte( (byte)'\\' );
+ stream.WriteByte( (byte)'0' );
+ }
+
+ else if (b == '\\' || b == '\'' || b == '\"')
+ {
+ stream.WriteByte( (byte)'\\' );
+ stream.WriteByte( b );
+ }
+ else
+ stream.WriteByte( b );
+ }
+ }
+
+ IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
+ {
+ if (nullVal)
+ return new MySqlBinary(type, true);
+
+ if (length == -1)
+ length = (long)stream.ReadFieldLength();
+
+ byte[] newBuff = new byte[length];
+ stream.Read(newBuff, 0, (int)length);
+ return new MySqlBinary(type, newBuff);
+ }
+
+ void IMySqlValue.SkipValue(MySqlStream stream)
+ {
+ long len = stream.ReadFieldLength();
+ stream.SkipBytes((int)len);
+ }
+
+ #endregion
+
+ public static void SetDSInfo(DataTable dsTable)
+ {
+ string[] types = new string[] { "BLOB", "TINYBLOB", "MEDIUMBLOB", "LONGBLOB" };
+ MySqlDbType[] dbtype = new MySqlDbType[] { MySqlDbType.Blob,
+ MySqlDbType.TinyBlob, MySqlDbType.MediumBlob, MySqlDbType.LongBlob };
+
+ // we use name indexing because this method will only be called
+ // when GetSchema is called for the DataSourceInformation
+ // collection and then it wil be cached.
+ for (int x=0; x < types.Length; x++)
+ {
+ DataRow row = dsTable.NewRow();
+ row["TypeName"] = types[x];
+ row["ProviderDbType"] = dbtype[x];
+ row["ColumnSize"] = 0;
+ row["CreateFormat"] = types[x];
+ row["CreateParameters"] = null;
+ row["DataType"] = "Byte";
+ row["IsAutoincrementable"] = false;
+ row["IsBestMatch"] = true;
+ row["IsCaseSensitive"] = false;
+ row["IsFixedLength"] = false;
+ row["IsFixedPrecisionScale"] = true;
+ row["IsLong"] = true;
+ row["IsNullable"] = true;
+ row["IsSearchable"] = true;
+ row["IsSearchableWithLike"] = true;
+ row["IsUnsigned"] = false;
+ row["MaximumScale"] = 0;
+ row["MinimumScale"] = 0;
+ row["IsConcurrencyType"] = DBNull.Value;
+ row["IsLiteralsSupported"] = false;
+ row["LiteralPrefix"] = null;
+ row["LiteralSuffix"] = null;
+ row["NativeDataType"] = null;
+ dsTable.Rows.Add(row);
+ }
+ }
+
+ }
+/*
+ /// <summary>
+ /// Summary description for MySqlBinary
+ /// </summary>
+ internal class MySqlBinary : MySqlValue
+ {
+ private byte[] mValue;
+ private bool isBinary;
+
+ public MySqlBinary(byte[] val, MySqlDbType type)
+ {
+ Value = val;
+ mySqlDbType = type;
+ }
+
+ internal string ToString( System.Text.Encoding encoding )
+ {
+ return encoding.GetString( (byte[])mValue );
+ }
+
+ internal override void Serialize(PacketWriter writer, bool binary, object ourValue, int length)
+ {
+ byte[] buffToWrite = null;
+
+ if (ourValue is System.Byte[])
+ buffToWrite = (byte[])ourValue;
+ else if (ourValue is String)
+ {
+ string s = (ourValue as string).Substring(0, length);
+ buffToWrite = stream.Encoding.GetBytes(s);
+ length = buffToWrite.Length;
+ }
+ else if (ourValue is Char[])
+ {
+ buffToWrite = stream.Encoding.GetBytes( (ourValue as char[]) );
+ length = buffToWrite.Length;
+ }
+
+ if ( buffToWrite == null )
+ throw new MySqlException( "Only byte arrays and strings can be serialized by MySqlBinary" );
+
+ if (binary)
+ {
+ stream.WriteLength( length );
+ stream.Write( buffToWrite, 0, length );
+ }
+ else
+ {
+ if ( stream.Version.isAtLeast(4,1,0))
+ stream.WriteStringNoNull( "_binary " );
+
+ stream.WriteByte( (byte)'\'');
+ EscapeByteArray( buffToWrite, length, writer );
+ stream.WriteByte((byte)'\'');
+ }
+ }
+
+ public bool IsBinary
+ {
+ get { return isBinary; }
+ set { isBinary = value; }
+ }
+
+ public byte[] Value
+ {
+ get { return mValue; }
+ set { mValue = value; objectValue = value; }
+ }
+
+ private void EscapeByteArray( byte[] bytes, int length, PacketWriter writer )
+ {
+ System.IO.MemoryStream ms = (System.IO.MemoryStream)stream.Stream;
+ ms.Capacity += (length * 2);
+
+ for (int x=0; x < length; x++)
+ {
+ byte b = bytes[x];
+ if (b == '\0')
+ {
+ stream.WriteByte( (byte)'\\' );
+ stream.WriteByte( (byte)'0' );
+ }
+
+ else if (b == '\\' || b == '\'' || b == '\"')
+ {
+ stream.WriteByte( (byte)'\\' );
+ stream.WriteByte( b );
+ }
+ else
+ stream.WriteByte( b );
+ }
+ }
+
+
+ internal override DbType DbType
+ {
+ get
+ {
+ if (isBinary) return DbType.Binary;
+ return DbType.String;
+ }
+ }
+
+
+ internal override Type SystemType
+ {
+ get { return typeof(byte[]); }
+ }
+
+ internal override string GetMySqlTypeName()
+ {
+ switch (mySqlDbType)
+ {
+ case MySqlDbType.TinyBlob: return "TINY_BLOB";
+ case MySqlDbType.MediumBlob: return "MEDIUM_BLOB";
+ case MySqlDbType.LongBlob: return "LONG_BLOB";
+ case MySqlDbType.Blob:
+ default:
+ return "BLOB";
+ }
+ }
+
+ internal override MySqlValue ReadValue(PacketReader reader, long length)
+ {
+ if (length == -1)
+ length = (long)stream.GetFieldLength();
+
+ byte[] newBuff = new byte[length];
+ stream.Read( ref newBuff, 0, length );
+ return new MySqlBinary( newBuff, mySqlDbType );
+ }
+
+ internal override void Skip(PacketReader reader)
+ {
+ long len = stream.GetFieldLength();
+ stream.Skip( len );
+ }
+
+ }*/
+}
Modified: trunk/mysqlclient/Types/MySqlByte.cs
===================================================================
--- trunk/mysqlclient/Types/MySqlByte.cs 2006-07-30 15:48:19 UTC (rev 285)
+++ trunk/mysqlclient/Types/MySqlByte.cs 2006-07-30 16:36:21 UTC (rev 286)
@@ -1,95 +1,95 @@
-// 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.Data;
+// 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.Data;
using MySql.Data.MySqlClient;
-using System.Globalization;
-
-namespace MySql.Data.Types
-{
- internal struct MySqlByte : IMySqlValue
- {
- private sbyte mValue;
- private bool isNull;
-
- public MySqlByte(bool isNull)
- {
- this.isNull = isNull;
- mValue = 0;
- }
-
- public MySqlByte(sbyte val)
- {
- this.isNull = false;
- mValue = val;
- }
-
- #region IMySqlValue Members
-
- public bool IsNull
- {
- get { return isNull; }
- }
-
- public MySql.Data.MySqlClient.MySqlDbType MySqlDbType
- {
- get { return MySqlDbType.Byte; }
- }
-
- public System.Data.DbType DbType
- {
- get { return DbType.SByte; }
- }
-
- object IMySqlValue.Value
- {
- get { return mValue; }
- }
-
- public sbyte Value
- {
- get { return mValue; }
- }
-
- public Type SystemType
- {
- get { return typeof(sbyte); }
- }
-
- public string MySqlTypeName
- {
- get { return "TINYINT"; }
- }
-
- void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
- {
- sbyte v = ((IConvertible)val).ToSByte(null);
- if (binary)
- stream.Write(BitConverter.GetBytes(v));
- else
- stream.WriteStringNoNull(v.ToString());
- }
-
- IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
- {
+using System.Globalization;
+
+namespace MySql.Data.Types
+{
+ internal struct MySqlByte : IMySqlValue
+ {
+ private sbyte mValue;
+ private bool isNull;
+
+ public MySqlByte(bool isNull)
+ {
+ this.isNull = isNull;
+ mValue = 0;
+ }
+
+ public MySqlByte(sbyte val)
+ {
+ this.isNull = false;
+ mValue = val;
+ }
+
+ #region IMySqlValue Members
+
+ public bool IsNull
+ {
+ get { return isNull; }
+ }
+
+ public MySql.Data.MySqlClient.MySqlDbType MySqlDbType
+ {
+ get { return MySqlDbType.Byte; }
+ }
+
+ public System.Data.DbType DbType
+ {
+ get { return DbType.SByte; }
+ }
+
+ object IMySqlValue.Value
+ {
+ get { return mValue; }
+ }
+
+ public sbyte Value
+ {
+ get { return mValue; }
+ }
+
+ public Type SystemType
+ {
+ get { return typeof(sbyte); }
+ }
+
+ public string MySqlTypeName
+ {
+ get { return "TINYINT"; }
+ }
+
+ void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
+ {
+ sbyte v = ((IConvertible)val).ToSByte(null);
+ if (binary)
+ stream.Write(BitConverter.GetBytes(v));
+ else
+ stream.WriteStringNoNull(v.ToString());
+ }
+
+ IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
+ {
if (nullVal)
return new MySqlByte(true);
@@ -99,102 +99,102 @@
{
string s = stream.ReadString(length);
return new MySqlByte(SByte.Parse(s, CultureInfo.InvariantCulture));
- }
- }
-
- void IMySqlValue.SkipValue(MySqlStream stream)
- {
- stream.ReadByte();
- }
-
- #endregion
-
- internal static void SetDSInfo(DataTable dsTable)
- {
- // we use name indexing because this method will only be called
- // when GetSchema is called for the DataSourceInformation
- // collection and then it wil be cached.
- DataRow row = dsTable.NewRow();
- row["TypeName"] = "TINYINT";
- row["ProviderDbType"] = MySqlDbType.Byte;
- row["ColumnSize"] = 0;
- row["CreateFormat"] = "TINYINT";
- row["CreateParameters"] = null;
- row["DataType"] = "System.SByte";
- row["IsAutoincrementable"] = true;
- row["IsBestMatch"] = true;
- row["IsCaseSensitive"] = false;
- row["IsFixedLength"] = true;
- row["IsFixedPrecisionScale"] = true;
- row["IsLong"] = false;
- row["IsNullable"] = true;
- row["IsSearchable"] = true;
- row["IsSearchableWithLike"] = false;
- row["IsUnsigned"] = false;
- row["MaximumScale"] = 0;
- row["MinimumScale"] = 0;
- row["IsConcurrencyType"] = DBNull.Value;
- row["IsLiteralsSupported"] = false;
- row["LiteralPrefix"] = null;
- row["LiteralSuffix"] = null;
- row["NativeDataType"] = null;
- dsTable.Rows.Add(row);
- }
- }
-/*
- /// <summary>
- /// Summary description for MySqlByte.
- /// </summary>
- internal class MySqlByte : MySqlValue
- {
- private sbyte mValue;
-
- public MySqlByte() : base()
- {
- dbType = DbType.SByte;
- mySqlDbType = MySqlDbType.Byte;
- }
-
- internal override void Serialize(PacketWriter writer, bool binary, object value, int length)
- {
- sbyte v = Convert.ToSByte( value );
- if (binary)
- stream.WriteByte( (byte)v );
- else
- stream.WriteStringNoNull( v.ToString() );
- }
-
-
- public sbyte Value
- {
- get { return mValue; }
- set { mValue = value; objectValue = value; }
- }
-
- internal override Type SystemType
- {
- get { return typeof(SByte); }
- }
-
- internal override string GetMySqlTypeName()
- {
- return "TINYINT";
- }
-
- internal override MySqlValue ReadValue(PacketReader reader, long length)
- {
- if (length == -1)
- Value = (sbyte)stream.ReadByte();
- else
- Value = SByte.Parse( stream.ReadString( length ) );
- return this;
- }
-
- internal override void Skip(PacketReader reader)
- {
- stream.ReadByte();
- }
-*/
-
- //}
-}
+ }
+ }
+
+ void IMySqlValue.SkipValue(MySqlStream stream)
+ {
+ stream.ReadByte();
+ }
+
+ #endregion
+
+ internal static void SetDSInfo(DataTable dsTable)
+ {
+ // we use name indexing because this method will only be called
+ // when GetSchema is called for the DataSourceInformation
+ // collection and then it wil be cached.
+ DataRow row = dsTable.NewRow();
+ row["TypeName"] = "TINYINT";
+ row["ProviderDbType"] = MySqlDbType.Byte;
+ row["ColumnSize"] = 0;
+ row["CreateFormat"] = "TINYINT";
+ row["CreateParameters"] = null;
+ row["DataType"] = "System.SByte";
+ row["IsAutoincrementable"] = true;
+ row["IsBestMatch"] = true;
+ row["IsCaseSensitive"] = false;
+ row["IsFixedLength"] = true;
+ row["IsFixedPrecisionScale"] = true;
+ row["IsLong"] = false;
+ row["IsNullable"] = true;
+ row["IsSearchable"] = true;
+ row["IsSearchableWithLike"] = false;
+ row["IsUnsigned"] = false;
+ row["MaximumScale"] = 0;
+ row["MinimumScale"] = 0;
+ row["IsConcurrencyType"] = DBNull.Value;
+ row["IsLiteralsSupported"] = false;
+ row["LiteralPrefix"] = null;
+ row["LiteralSuffix"] = null;
+ row["NativeDataType"] = null;
+ dsTable.Rows.Add(row);
+ }
+ }
+/*
+ /// <summary>
+ /// Summary description for MySqlByte.
+ /// </summary>
+ internal class MySqlByte : MySqlValue
+ {
+ private sbyte mValue;
+
+ public MySqlByte() : base()
+ {
+ dbType = DbType.SByte;
+ mySqlDbType = MySqlDbType.Byte;
+ }
+
+ internal override void Serialize(PacketWriter writer, bool binary, object value, int length)
+ {
+ sbyte v = Convert.ToSByte( value );
+ if (binary)
+ stream.WriteByte( (byte)v );
+ else
+ stream.WriteStringNoNull( v.ToString() );
+ }
+
+
+ public sbyte Value
+ {
+ get { return mValue; }
+ set { mValue = value; objectValue = value; }
+ }
+
+ internal override Type SystemType
+ {
+ get { return typeof(SByte); }
+ }
+
+ internal override string GetMySqlTypeName()
+ {
+ return "TINYINT";
+ }
+
+ internal override MySqlValue ReadValue(PacketReader reader, long length)
+ {
+ if (length == -1)
+ Value = (sbyte)stream.ReadByte();
+ else
+ Value = SByte.Parse( stream.ReadString( length ) );
+ return this;
+ }
+
+ internal override void Skip(PacketReader reader)
+ {
+ stream.ReadByte();
+ }
+*/
+
+ //}
+}
Modified: trunk/mysqlclient/Types/MySqlTime.cs
===================================================================
--- trunk/mysqlclient/Types/MySqlTime.cs 2006-07-30 15:48:19 UTC (rev 285)
+++ trunk/mysqlclient/Types/MySqlTime.cs 2006-07-30 16:36:21 UTC (rev 286)
@@ -1,317 +1,317 @@
-// 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.Data;
-using MySql.Data.MySqlClient;
-
-namespace MySql.Data.Types
-{
-
- internal struct MySqlTimeSpan : IMySqlValue
- {
- private TimeSpan mValue;
- private bool isNull;
-
- public MySqlTimeSpan(bool isNull)
- {
- this.isNull = isNull;
- mValue = TimeSpan.MinValue;
- }
-
- public MySqlTimeSpan(TimeSpan val)
- {
- this.isNull = false;
- mValue = val;
- }
-
- #region IMySqlValue Members
-
- public bool IsNull
- {
- get { return isNull; }
- }
-
- public MySql.Data.MySqlClient.MySqlDbType MySqlDbType
- {
- get { return MySqlDbType.Time; }
- }
-
- public System.Data.DbType DbType
- {
- get { return DbType.Time; }
- }
-
- object IMySqlValue.Value
- {
- get { return mValue; }
- }
-
- public TimeSpan Value
- {
- get { return mValue; }
- }
-
- public Type SystemType
- {
- get { return typeof(TimeSpan); }
- }
-
- public string MySqlTypeName
- {
- get { return "TIME"; }
- }
-
- void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
- {
- if (! (val is TimeSpan))
- throw new MySqlException("Only TimeSpan objects can be serialized by MySqlTimeSpan");
-
- TimeSpan ts = (TimeSpan)val;
- if (binary)
- {
+// 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.Data;
+using MySql.Data.MySqlClient;
+
+namespace MySql.Data.Types
+{
+
+ internal struct MySqlTimeSpan : IMySqlValue
+ {
+ private TimeSpan mValue;
+ private bool isNull;
+
+ public MySqlTimeSpan(bool isNull)
+ {
+ this.isNull = isNull;
+ mValue = TimeSpan.MinValue;
+ }
+
+ public MySqlTimeSpan(TimeSpan val)
+ {
+ this.isNull = false;
+ mValue = val;
+ }
+
+ #region IMySqlValue Members
+
+ public bool IsNull
+ {
+ get { return isNull; }
+ }
+
+ public MySql.Data.MySqlClient.MySqlDbType MySqlDbType
+ {
+ get { return MySqlDbType.Time; }
+ }
+
+ public System.Data.DbType DbType
+ {
+ get { return DbType.Time; }
+ }
+
+ object IMySqlValue.Value
+ {
+ get { return mValue; }
+ }
+
+ public TimeSpan Value
+ {
+ get { return mValue; }
+ }
+
+ public Type SystemType
+ {
+ get { return typeof(TimeSpan); }
+ }
+
+ public string MySqlTypeName
+ {
+ get { return "TIME"; }
+ }
+
+ void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
+ {
+ if (! (val is TimeSpan))
+ throw new MySqlException("Only TimeSpan objects can be serialized by MySqlTimeSpan");
+
+ TimeSpan ts = (TimeSpan)val;
+ if (binary)
+ {
stream.WriteByte(8);
stream.WriteByte((byte)(ts.TotalSeconds < 0 ? 1 : 0));
stream.WriteInteger(ts.Days, 4);
stream.WriteByte((byte)ts.Hours);
stream.WriteByte((byte)ts.Minutes);
- stream.WriteByte((byte)ts.Seconds);
- }
- else
+ stream.WriteByte((byte)ts.Seconds);
+ }
+ else
{
- stream.WriteStringNoNull(String.Format("'{0} {1:00}:{2:00}:{3:00}.{4}'",
- ts.Days, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds ) );
- }
- }
-
-
- IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
- {
- if (nullVal) return new MySqlTimeSpan(true);
-
- if (length >= 0)
+ stream.WriteStringNoNull(String.Format("'{0} {1:00}:{2:00}:{3:00}.{4}'",
+ ts.Days, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds ) );
+ }
+ }
+
+
+ IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
+ {
+ if (nullVal) return new MySqlTimeSpan(true);
+
+ if (length >= 0)
{
string value = stream.ReadString(length);
- ParseMySql(value, stream.Version.isAtLeast(4, 1, 0));
- return this;
+ ParseMySql(value, stream.Version.isAtLeast(4, 1, 0));
+ return this;
}
- long bufLength = stream.ReadByte();
- int negate = 0;
+ long bufLength = stream.ReadByte();
+ int negate = 0;
if (bufLength > 0)
- negate = stream.ReadByte();
-
- isNull = false;
- if (bufLength == 0)
- isNull = true;
+ negate = stream.ReadByte();
+
+ isNull = false;
+ if (bufLength == 0)
+ isNull = true;
else if (bufLength == 5)
- mValue = new TimeSpan(stream.ReadInteger(4), 0, 0, 0);
+ mValue = new TimeSpan(stream.ReadInteger(4), 0, 0, 0);
else if (bufLength == 8)
mValue = new TimeSpan(stream.ReadInteger(4),
- stream.ReadByte(), stream.ReadByte(), stream.ReadByte());
+ stream.ReadByte(), stream.ReadByte(), stream.ReadByte());
else
mValue = new TimeSpan(stream.ReadInteger(4),
stream.ReadByte(), stream.ReadByte(), stream.ReadByte(),
- stream.ReadInteger(4) / 1000000);
-
- if (negate == 1)
- mValue = mValue.Negate();
- return this;
- }
-
- void IMySqlValue.SkipValue(MySqlStream stream)
- {
- int len = stream.ReadByte();
- stream.SkipBytes(len);
- }
-
- #endregion
-
- internal static void SetDSInfo(DataTable dsTable)
- {
- // we use name indexing because this method will only be called
- // when GetSchema is called for the DataSourceInformation
- // collection and then it wil be cached.
- DataRow row = dsTable.NewRow();
- row["TypeName"] = "TIME";
- row["ProviderDbType"] = MySqlDbType.Time;
- row["ColumnSize"] = 0;
- row["CreateFormat"] = "TIME";
- row["CreateParameters"] = null;
- row["DataType"] = "System.TimeSpan";
- row["IsAutoincrementable"] = false;
- row["IsBestMatch"] = true;
- row["IsCaseSensitive"] = false;
- row["IsFixedLength"] = true;
- row["IsFixedPrecisionScale"] = true;
- row["IsLong"] = false;
- row["IsNullable"] = true;
- row["IsSearchable"] = true;
- row["IsSearchableWithLike"] = false;
- row["IsUnsigned"] = false;
- row["MaximumScale"] = 0;
- row["MinimumScale"] = 0;
- row["IsConcurrencyType"] = DBNull.Value;
- row["IsLiteralsSupported"] = false;
- row["LiteralPrefix"] = null;
- row["LiteralSuffix"] = null;
- row["NativeDataType"] = null;
- dsTable.Rows.Add(row);
- }
-
- public override string ToString()
- {
- return String.Format("{0} {1:00}:{2:00}:{3:00}.{4}",
- mValue.Days, mValue.Hours, mValue.Minutes, mValue.Seconds, mValue.Milliseconds );
- }
-
- private void ParseMySql( string s, bool is41 )
- {
- string[] parts = s.Split(':');
- int hours = Int32.Parse( parts[0] );
- int mins = Int32.Parse( parts[1] );
- int secs = Int32.Parse( parts[2] );
- int days = hours / 24;
- hours = hours - (days * 24);
- mValue = new TimeSpan( days, hours, mins, secs, 0 );
- isNull = false;
- }
- }
-/*
-
- /// <summary>
- /// Summary description for MySqlDateTime.
- /// </summary>
- internal class MySqlTimeSpan : MySqlValue
- {
- private TimeSpan mValue;
-
- public MySqlTimeSpan()
- {
- dbType = DbType.Time;
- mySqlDbType = MySqlDbType.Time;
- }
-
- public MySqlTimeSpan(TimeSpan val) : this()
- {
- mValue = val;
- }
-
- internal override void Serialize(PacketWriter writer, bool binary, object value, int length)
- {
- if (! (value is TimeSpan))
- throw new MySqlException("Only TimeSpan objects can be serialized by MySqlTimeSpan");
-
- TimeSpan ts = (TimeSpan)value;
- if (binary)
- {
- stream.WriteByte( 8 );
- stream.WriteByte( (byte)(ts.TotalSeconds < 0 ? 1 : 0 ));
- stream.WriteInteger( ts.Days, 4 );
- stream.WriteByte( (byte)ts.Hours );
- stream.WriteByte( (byte)ts.Minutes );
- stream.WriteByte( (byte)ts.Seconds );
- }
- else
- {
- stream.WriteStringNoNull( String.Format("'{0} {1:00}:{2:00}:{3:00}.{4}'",
- ts.Days, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds ) );
- }
- }
-
-
- public override string ToString()
- {
- return String.Format("{0} {1:00}:{2:00}:{3:00}.{4}",
- mValue.Days, mValue.Hours, mValue.Minutes, mValue.Seconds, mValue.Milliseconds );
- }
-
-
- internal override string GetMySqlTypeName()
- {
- return "TIME";
- }
-
- public TimeSpan Value
- {
- get { return mValue; }
- set { mValue = value; objectValue = value;}
- }
-
- private void ParseMySql( string s, bool is41 )
- {
- string[] parts = s.Split(':');
- int hours = Int32.Parse( parts[0] );
- int mins = Int32.Parse( parts[1] );
- int secs = Int32.Parse( parts[2] );
- int days = hours / 24;
- hours = hours - (days * 24);
- Value = new TimeSpan( days, hours, mins, secs, 0 );
- }
-
- internal override Type SystemType
- {
- get { return typeof(TimeSpan); }
- }
-
- internal override MySqlValue ReadValue(PacketReader reader, long length)
- {
- if (length >= 0)
- {
- string value = stream.ReadString( length );
- ParseMySql( value, stream.Version.isAtLeast(4,1,0));
- return this;
- }
-
- long bufLength = stream.ReadByte();
- int negate = 0;
- if (bufLength > 0)
- negate = stream.ReadByte();
-
- if (bufLength == 0)
- IsNull = true;
- else if (bufLength == 5)
- Value = new TimeSpan( stream.ReadInteger( 4 ), 0, 0, 0 );
- else if (bufLength == 8)
- Value = new TimeSpan( stream.ReadInteger(4),
- stream.ReadByte(), stream.ReadByte(), stream.ReadByte() );
- else
- Value = new TimeSpan( stream.ReadInteger(4),
- stream.ReadByte(), stream.ReadByte(), stream.ReadByte(),
- stream.ReadInteger(4) / 1000000 );
-
- if (negate == 1)
- Value = mValue.Negate();
- return this;
- }
-
- public string ToMySqlString(bool is41)
- {
- return mValue.ToString();
- }
-
- internal override void Skip(PacketReader reader)
- {
- long len = (long)stream.ReadByte();
- stream.Skip( len );
- }
-
- }*/
-}
+ stream.ReadInteger(4) / 1000000);
+
+ if (negate == 1)
+ mValue = mValue.Negate();
+ return this;
+ }
+
+ void IMySqlValue.SkipValue(MySqlStream stream)
+ {
+ int len = stream.ReadByte();
+ stream.SkipBytes(len);
+ }
+
+ #endregion
+
+ internal static void SetDSInfo(DataTable dsTable)
+ {
+ // we use name indexing because this method will only be called
+ // when GetSchema is called for the DataSourceInformation
+ // collection and then it wil be cached.
+ DataRow row = dsTable.NewRow();
+ row["TypeName"] = "TIME";
+ row["ProviderDbType"] = MySqlDbType.Time;
+ row["ColumnSize"] = 0;
+ row["CreateFormat"] = "TIME";
+ row["CreateParameters"] = null;
+ row["DataType"] = "System.TimeSpan";
+ row["IsAutoincrementable"] = false;
+ row["IsBestMatch"] = true;
+ row["IsCaseSensitive"] = false;
+ row["IsFixedLength"] = true;
+ row["IsFixedPrecisionScale"] = true;
+ row["IsLong"] = false;
+ row["IsNullable"] = true;
+ row["IsSearchable"] = true;
+ row["IsSearchableWithLike"] = false;
+ row["IsUnsigned"] = false;
+ row["MaximumScale"] = 0;
+ row["MinimumScale"] = 0;
+ row["IsConcurrencyType"] = DBNull.Value;
+ row["IsLiteralsSupported"] = false;
+ row["LiteralPrefix"] = null;
+ row["LiteralSuffix"] = null;
+ row["NativeDataType"] = null;
+ dsTable.Rows.Add(row);
+ }
+
+ public override string ToString()
+ {
+ return String.Format("{0} {1:00}:{2:00}:{3:00}.{4}",
+ mValue.Days, mValue.Hours, mValue.Minutes, mValue.Seconds, mValue.Milliseconds );
+ }
+
+ private void ParseMySql( string s, bool is41 )
+ {
+ string[] parts = s.Split(':');
+ int hours = Int32.Parse( parts[0] );
+ int mins = Int32.Parse( parts[1] );
+ int secs = Int32.Parse( parts[2] );
+ int days = hours / 24;
+ hours = hours - (days * 24);
+ mValue = new TimeSpan( days, hours, mins, secs, 0 );
+ isNull = false;
+ }
+ }
+/*
+
+ /// <summary>
+ /// Summary description for MySqlDateTime.
+ /// </summary>
+ internal class MySqlTimeSpan : MySqlValue
+ {
+ private TimeSpan mValue;
+
+ public MySqlTimeSpan()
+ {
+ dbType = DbType.Time;
+ mySqlDbType = MySqlDbType.Time;
+ }
+
+ public MySqlTimeSpan(TimeSpan val) : this()
+ {
+ mValue = val;
+ }
+
+ internal override void Serialize(PacketWriter writer, bool binary, object value, int length)
+ {
+ if (! (value is TimeSpan))
+ throw new MySqlException("Only TimeSpan objects can be serialized by MySqlTimeSpan");
+
+ TimeSpan ts = (TimeSpan)value;
+ if (binary)
+ {
+ stream.WriteByte( 8 );
+ stream.WriteByte( (byte)(ts.TotalSeconds < 0 ? 1 : 0 ));
+ stream.WriteInteger( ts.Days, 4 );
+ stream.WriteByte( (byte)ts.Hours );
+ stream.WriteByte( (byte)ts.Minutes );
+ stream.WriteByte( (byte)ts.Seconds );
+ }
+ else
+ {
+ stream.WriteStringNoNull( String.Format("'{0} {1:00}:{2:00}:{3:00}.{4}'",
+ ts.Days, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds ) );
+ }
+ }
+
+
+ public override string ToString()
+ {
+ return String.Format("{0} {1:00}:{2:00}:{3:00}.{4}",
+ mValue.Days, mValue.Hours, mValue.Minutes, mValue.Seconds, mValue.Milliseconds );
+ }
+
+
+ internal override string GetMySqlTypeName()
+ {
+ return "TIME";
+ }
+
+ public TimeSpan Value
+ {
+ get { return mValue; }
+ set { mValue = value; objectValue = value;}
+ }
+
+ private void ParseMySql( string s, bool is41 )
+ {
+ string[] parts = s.Split(':');
+ int hours = Int32.Parse( parts[0] );
+ int mins = Int32.Parse( parts[1] );
+ int secs = Int32.Parse( parts[2] );
+ int days = hours / 24;
+ hours = hours - (days * 24);
+ Value = new TimeSpan( days, hours, mins, secs, 0 );
+ }
+
+ internal override Type SystemType
+ {
+ get { return typeof(TimeSpan); }
+ }
+
+ internal override MySqlValue ReadValue(PacketReader reader, long length)
+ {
+ if (length >= 0)
+ {
+ string value = stream.ReadString( length );
+ ParseMySql( value, stream.Version.isAtLeast(4,1,0));
+ return this;
+ }
+
+ long bufLength = stream.ReadByte();
+ int negate = 0;
+ if (bufLength > 0)
+ negate = stream.ReadByte();
+
+ if (bufLength == 0)
+ IsNull = true;
+ else if (bufLength == 5)
+ Value = new TimeSpan( stream.ReadInteger( 4 ), 0, 0, 0 );
+ else if (bufLength == 8)
+ Value = new TimeSpan( stream.ReadInteger(4),
+ stream.ReadByte(), stream.ReadByte(), stream.ReadByte() );
+ else
+ Value = new TimeSpan( stream.ReadInteger(4),
+ stream.ReadByte(), stream.ReadByte(), stream.ReadByte(),
+ stream.ReadInteger(4) / 1000000 );
+
+ if (negate == 1)
+ Value = mValue.Negate();
+ return this;
+ }
+
+ public string ToMySqlString(bool is41)
+ {
+ return mValue.ToString();
+ }
+
+ internal override void Skip(PacketReader reader)
+ {
+ long len = (long)stream.ReadByte();
+ stream.Skip( len );
+ }
+
+ }*/
+}
Deleted: trunk/mysqlclient/Types/NumberFormat.cs
===================================================================
--- trunk/mysqlclient/Types/NumberFormat.cs 2006-07-30 15:48:19 UTC (rev 285)
+++ trunk/mysqlclient/Types/NumberFormat.cs 2006-07-30 16:36:21 UTC (rev 286)
@@ -1,34 +0,0 @@
-using System;
-using System.Globalization;
-
-namespace MySql.Data.Types
-{
- /// <summary>
- /// Summary description for NumberFormat.
- /// </summary>
- internal class NumberFormat
- {
- private static NumberFormat mysql;
- private NumberFormatInfo numberFormatInfo;
-
-
- private NumberFormat()
- {
- numberFormatInfo = null;
- }
-
- public static NumberFormat MySql()
- {
- if (mysql == null)
- {
- mysql = new NumberFormat();
- }
- return mysql;
- }
-
- public NumberFormatInfo NumberFormatInfo
- {
- get { return numberFormatInfo; }
- }
- }
-}
Modified: trunk/mysqlclient/common/SHA1.cs
===================================================================
--- trunk/mysqlclient/common/SHA1.cs 2006-07-30 15:48:19 UTC (rev 285)
+++ trunk/mysqlclient/common/SHA1.cs 2006-07-30 16:36:21 UTC (rev 286)
@@ -1,4 +1,4 @@
-// Copyright (C) 2004-2005 MySQL AB
+// 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
Modified: trunk/mysqlclient/common/WinCE.cs
===================================================================
--- trunk/mysqlclient/common/WinCE.cs 2006-07-30 15:48:19 UTC (rev 285)
+++ trunk/mysqlclient/common/WinCE.cs 2006-07-30 16:36:21 UTC (rev 286)
@@ -1,4 +1,4 @@
-// Copyright (C) 2004 MySQL AB
+// 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
| Thread |
|---|
| • Connector/NET commit: r286 - in trunk: TestSuite mysqlclient mysqlclient/Types mysqlclient/common | rburnett | 30 Jul |