#At file:///C:/Users/Reggie/work/connector-net/6.3/ based on revid:reggie.burnett@stripped
1019 Reggie Burnett 2011-06-23
tabified a few files, made a couple of enhancements in basetest to help our test suite run better
modified:
Tests/MySql.Data.Tests/AsyncTests.cs
Tests/MySql.Data.Tests/BaseTest.cs
Tests/MySql.Data.Tests/BlobTests.cs
Tests/MySql.Data.Tests/BulkLoading.cs
Tests/MySql.Data.Tests/CharacterSetTests.cs
Tests/MySql.Data.Tests/CommandBuilderTests.cs
Tests/MySql.Data.Tests/CommandTests.cs
Tests/MySql.Data.Tests/ConnectionTests.cs
=== modified file 'Tests/MySql.Data.Tests/AsyncTests.cs'
=== modified file 'Tests/MySql.Data.Tests/AsyncTests.cs'
--- a/Tests/MySql.Data.Tests/AsyncTests.cs 2011-06-21 18:51:27 +0000
+++ b/Tests/MySql.Data.Tests/AsyncTests.cs 2011-06-23 15:01:13 +0000
@@ -60,7 +60,7 @@
[Test]
public void ExecuteReader()
{
- if (Version < new Version(5, 0)) return;
+ if (Version < new Version(5, 0)) return;
execSQL("CREATE TABLE test (id int)");
execSQL("CREATE PROCEDURE spTest() BEGIN INSERT INTO test VALUES(1); " +
@@ -77,7 +77,7 @@
}
using (MySqlDataReader reader = proc.EndExecuteReader(iar))
- {
+ {
Assert.IsNotNull(reader);
Assert.IsTrue(count > 0, "count > 0");
Assert.IsTrue(reader.Read(), "can read");
@@ -100,10 +100,10 @@
IAsyncResult r = cmd.BeginExecuteReader();
try
{
- using (MySqlDataReader reader = cmd.EndExecuteReader(r))
- {
- Assert.Fail("EndExecuteReader should have thrown an exception");
- }
+ using (MySqlDataReader reader = cmd.EndExecuteReader(r))
+ {
+ Assert.Fail("EndExecuteReader should have thrown an exception");
+ }
}
catch (MySqlException)
{
=== modified file 'Tests/MySql.Data.Tests/BaseTest.cs'
--- a/Tests/MySql.Data.Tests/BaseTest.cs 2011-06-21 18:51:27 +0000
+++ b/Tests/MySql.Data.Tests/BaseTest.cs 2011-06-23 15:01:13 +0000
@@ -32,37 +32,37 @@
namespace MySql.Data.MySqlClient.Tests
{
- /// <summary>
- /// Summary description for BaseTest.
- /// </summary>
- public class BaseTest
- {
- //statics
- protected static int maxPacketSize;
- protected static MySqlConnection rootConn;
- protected static string host;
- protected static string user;
- protected static string password;
- protected static int port;
- protected static string pipeName;
- protected static string memoryName;
- protected static string rootUser;
- protected static string rootPassword;
- protected static string database0;
- protected static string database1;
- protected static Version version;
-
- protected string table;
- protected string csAdditions = String.Empty;
- protected MySqlConnection conn;
- protected bool accessToMySqlDb;
- private int numProcessesRunning;
-
- public BaseTest()
- {
+ /// <summary>
+ /// Summary description for BaseTest.
+ /// </summary>
+ public class BaseTest
+ {
+ //statics
+ protected static int maxPacketSize;
+ protected static MySqlConnection rootConn;
+ protected static string host;
+ protected static string user;
+ protected static string password;
+ protected static int port;
+ protected static string pipeName;
+ protected static string memoryName;
+ protected static string rootUser;
+ protected static string rootPassword;
+ protected static string database0;
+ protected static string database1;
+ protected static Version version;
+
+ protected string table;
+ protected string csAdditions = String.Empty;
+ protected MySqlConnection conn;
+ protected bool accessToMySqlDb;
+ private int numProcessesRunning;
+
+ public BaseTest()
+ {
if (host == null)
LoadStaticConfiguration();
- }
+ }
protected virtual void LoadStaticConfiguration()
{
@@ -73,7 +73,7 @@
port = 3306;
rootUser = "root";
rootPassword = "";
- string strPort = null;
+ string strPort = null;
#if !CF
host = ConfigurationManager.AppSettings["host"];
@@ -102,253 +102,292 @@
database1 = String.Format("db{0}{1}{2}-b", versionParts[0], versionParts[1], port - 3300);
}
- string connStr = GetConnectionString(rootUser, rootPassword, false);
- rootConn = new MySqlConnection(connStr + ";database=mysql");
- rootConn.Open();
-
- if (rootConn.ServerVersion.StartsWith("5"))
- {
- // run all tests in strict mode
- MySqlCommand cmd = new MySqlCommand("SET GLOBAL SQL_MODE=STRICT_ALL_TABLES", rootConn);
- cmd.ExecuteNonQuery();
- }
- }
-
- #region Properties
-
- protected Version Version
- {
- get
- {
- if (version == null)
- {
- string versionString = rootConn.ServerVersion;
- int i = 0;
- while (i < versionString.Length &&
- (Char.IsDigit(versionString[i]) || versionString[i] == '.'))
- i++;
- version = new Version(versionString.Substring(0, i));
- }
- return version;
- }
- }
-
- #endregion
-
- protected virtual string GetConnectionInfo()
- {
- return String.Format("protocol=sockets;port={0};", port);
- }
-
- protected string GetConnectionString(string userId, string pw, bool includedb)
- {
- Debug.Assert(userId != null);
- string connStr = String.Format("server={0};user id={1};pooling=false;" +
- "persist security info=true;connection reset=true;allow user variables=true;",
- host, userId);
- if (pw != null)
- connStr += String.Format(";password={0};", pw);
- if (includedb)
- connStr += String.Format("database={0};", database0);
- connStr += GetConnectionInfo();
- connStr += csAdditions;
- return connStr;
- }
-
- protected string GetConnectionString(bool includedb)
- {
- return GetConnectionString(user, password, includedb);
- }
-
- protected string GetPoolingConnectionString()
- {
- string s = GetConnectionString(true);
- s = s.Replace("pooling=false", "pooling=true");
- return s;
- }
-
- protected void Open()
- {
- string connString = GetConnectionString(true);
- conn = new MySqlConnection(connString);
- conn.Open();
- }
-
- protected void SetAccountPerms(bool includeProc)
- {
- // now allow our user to access them
- suExecSQL(String.Format(@"GRANT ALL ON `{0}`.* to 'test'@'localhost'
+ //string connStr = GetConnectionString(rootUser, rootPassword, false);
+ //rootConn = new MySqlConnection(connStr + ";database=mysql");
+ //rootConn.Open();
+
+ //if (rootConn.ServerVersion.StartsWith("5"))
+ //{
+ // // run all tests in strict mode
+ // MySqlCommand cmd = new MySqlCommand("SET GLOBAL SQL_MODE=STRICT_ALL_TABLES", rootConn);
+ // cmd.ExecuteNonQuery();
+ //}
+ }
+
+ #region Properties
+
+ protected Version Version
+ {
+ get
+ {
+ if (version == null)
+ {
+ string versionString = rootConn.ServerVersion;
+ int i = 0;
+ while (i < versionString.Length &&
+ (Char.IsDigit(versionString[i]) || versionString[i] == '.'))
+ i++;
+ version = new Version(versionString.Substring(0, i));
+ }
+ return version;
+ }
+ }
+
+ #endregion
+
+ protected virtual string GetConnectionInfo()
+ {
+ return String.Format("protocol=sockets;port={0};", port);
+ }
+
+ protected string GetConnectionString(string userId, string pw, bool includedb)
+ {
+ Debug.Assert(userId != null);
+ string connStr = String.Format("server={0};user id={1};pooling=false;" +
+ "persist security info=true;connection reset=true;allow user variables=true;",
+ host, userId);
+ if (pw != null)
+ connStr += String.Format(";password={0};", pw);
+ if (includedb)
+ connStr += String.Format("database={0};", database0);
+ connStr += GetConnectionInfo();
+ connStr += csAdditions;
+ return connStr;
+ }
+
+ protected string GetConnectionString(bool includedb)
+ {
+ return GetConnectionString(user, password, includedb);
+ }
+
+ protected string GetPoolingConnectionString()
+ {
+ string s = GetConnectionString(true);
+ s = s.Replace("pooling=false", "pooling=true");
+ return s;
+ }
+
+ protected void Open()
+ {
+ string connString = GetConnectionString(true);
+ conn = new MySqlConnection(connString);
+ conn.Open();
+ }
+
+ protected void SetAccountPerms(bool includeProc)
+ {
+ // now allow our user to access them
+ suExecSQL(String.Format(@"GRANT ALL ON `{0}`.* to 'test'@'localhost'
identified by 'test'", database0));
- suExecSQL(String.Format(@"GRANT SELECT ON `{0}`.* to 'test'@'localhost'
+ suExecSQL(String.Format(@"GRANT SELECT ON `{0}`.* to 'test'@'localhost'
identified by 'test'", database1));
- if (Version.Major >= 5)
- suExecSQL(String.Format(@"GRANT EXECUTE ON `{0}`.* to 'test'@'localhost'
- identified by 'test'", database1));
-
- if (includeProc)
- {
- // now allow our user to access them
- suExecSQL(@"GRANT ALL ON mysql.proc to 'test'@'localhost' identified by 'test'");
- }
-
- suExecSQL("FLUSH PRIVILEGES");
- }
-
- [SetUp]
- public virtual void Setup()
- {
- Assembly executingAssembly = Assembly.GetExecutingAssembly();
+ if (Version.Major >= 5)
+ suExecSQL(String.Format(@"GRANT EXECUTE ON `{0}`.* to 'test'@'localhost'
+ identified by 'test'", database1));
+
+ if (includeProc)
+ {
+ // now allow our user to access them
+ suExecSQL(@"GRANT ALL ON mysql.proc to 'test'@'localhost' identified by 'test'");
+ }
+
+ suExecSQL("FLUSH PRIVILEGES");
+ }
+
+ [SetUp]
+ public virtual void Setup()
+ {
+ Assembly executingAssembly = Assembly.GetExecutingAssembly();
#if !CF
- Stream stream = executingAssembly.GetManifestResourceStream("MySql.Data.MySqlClient.Tests.Properties.Setup.sql");
+ Stream stream = executingAssembly.GetManifestResourceStream("MySql.Data.MySqlClient.Tests.Properties.Setup.sql");
#else
- Stream stream = executingAssembly.GetManifestResourceStream("MySql.Data.CF.Tests.Properties.Setup.sql");
+ Stream stream = executingAssembly.GetManifestResourceStream("MySql.Data.CF.Tests.Properties.Setup.sql");
#endif
- StreamReader sr = new StreamReader(stream);
- string sql = sr.ReadToEnd();
- sr.Close();
-
- SetAccountPerms(accessToMySqlDb);
- sql = sql.Replace("[database0]", database0);
- sql = sql.Replace("[database1]", database1);
-
- ExecuteSQLAsRoot(sql);
- Open();
- numProcessesRunning = CountProcesses();
- }
-
- protected void ExecuteSQLAsRoot(string sql)
- {
- MySqlScript s = new MySqlScript(rootConn, sql);
- s.Execute();
- }
-
- [TearDown]
- public virtual void Teardown()
- {
- // wait up to 5 seconds for our connection to close
- int procs = CountProcesses();
- for (int x = 0; x < 50; x++)
- {
- if (procs == numProcessesRunning) break;
- System.Threading.Thread.Sleep(100);
- procs = CountProcesses();
- }
- Assert.AreEqual(numProcessesRunning, procs, "Too many processes still running");
-
- conn.Close();
- if (Version.Major < 5)
- suExecSQL("REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'test'");
- else
- suExecSQL("DROP USER 'test'@'localhost'");
-
- DropDatabase(database0);
- DropDatabase(database1);
- }
-
- private void DropDatabase(string name)
- {
- for (int i = 0; i < 5; i++)
- {
- try
- {
- suExecSQL(String.Format("DROP DATABASE IF EXISTS `{0}`", name));
- return;
- }
- catch (Exception)
- {
- System.Threading.Thread.Sleep(1000);
- }
- }
- Assert.Fail("Unable to drop database " + name);
- }
-
- protected void KillConnection(MySqlConnection c)
- {
- int threadId = c.ServerThread;
- MySqlCommand cmd = new MySqlCommand("KILL " + threadId, conn);
- cmd.ExecuteNonQuery();
-
- // the kill flag might need a little prodding to do its thing
- try
- {
- cmd.CommandText = "SELECT 1";
- cmd.Connection = c;
- cmd.ExecuteNonQuery();
- }
- catch (Exception) { }
-
- // now wait till the process dies
- bool processStillAlive = false;
- while (true)
- {
- MySqlDataAdapter da = new MySqlDataAdapter("SHOW PROCESSLIST", conn);
- DataTable dt = new DataTable();
- da.Fill(dt);
- foreach (DataRow row in dt.Rows)
- if (row["Id"].Equals(threadId))
- processStillAlive = true;
- if (!processStillAlive) break;
- System.Threading.Thread.Sleep(500);
- }
- }
-
- protected void KillPooledConnection(string connStr)
- {
- MySqlConnection c = new MySqlConnection(connStr);
- c.Open();
- KillConnection(c);
- }
-
- protected void createTable(string sql, string engine)
- {
- if (Version >= new Version(4,1))
- sql += " ENGINE=" + engine;
- else
- sql += " TYPE=" + engine;
- execSQL(sql);
- }
-
- protected void suExecSQL(string sql)
- {
- Debug.Assert(rootConn != null);
- MySqlCommand cmd = new MySqlCommand(sql, rootConn);
- cmd.ExecuteNonQuery();
- }
-
- protected void execSQL(string sql)
- {
- MySqlCommand cmd = new MySqlCommand(sql, conn);
- cmd.ExecuteNonQuery();
- }
-
- protected IDataReader execReader(string sql)
- {
- MySqlCommand cmd = new MySqlCommand(sql, conn);
- return cmd.ExecuteReader();
- }
-
- protected int CountProcesses()
- {
- MySqlDataAdapter da = new MySqlDataAdapter("SHOW PROCESSLIST", rootConn);
- DataTable dt = new DataTable();
- da.Fill(dt);
- return dt.Rows.Count;
- }
-
- protected bool TableExists(string tableName)
- {
- string[] restrictions = new string[4];
- restrictions[2] = tableName;
- DataTable dt = conn.GetSchema("Tables", restrictions);
- return dt.Rows.Count > 0;
- }
-
- protected DataTable FillTable(string sql)
- {
- MySqlDataAdapter da = new MySqlDataAdapter(sql, conn);
- DataTable dt = new DataTable();
- da.Fill(dt);
- return dt;
- }
- }
+ StreamReader sr = new StreamReader(stream);
+ string sql = sr.ReadToEnd();
+ sr.Close();
+
+
+ string connStr = GetConnectionString(rootUser, rootPassword, false);
+ rootConn = new MySqlConnection(connStr + ";database=mysql");
+ rootConn.Open();
+
+ if (rootConn.ServerVersion.StartsWith("5"))
+ {
+ // run all tests in strict mode
+ MySqlCommand cmd = new MySqlCommand("SET GLOBAL SQL_MODE=STRICT_ALL_TABLES", rootConn);
+ cmd.ExecuteNonQuery();
+ }
+
+
+ SetAccountPerms(accessToMySqlDb);
+ sql = sql.Replace("[database0]", database0);
+ sql = sql.Replace("[database1]", database1);
+
+ ExecuteSQLAsRoot(sql);
+ Open();
+ numProcessesRunning = CountProcesses();
+ }
+
+ protected void ExecuteSQLAsRoot(string sql)
+ {
+ MySqlScript s = new MySqlScript(rootConn, sql);
+ s.Execute();
+ }
+
+ private void CheckOrphanedConnections()
+ {
+ // wait up to 5 seconds for our connection to close
+ int procs = CountProcesses();
+ for (int x = 0; x < 50; x++)
+ {
+ if (procs == numProcessesRunning) break;
+ System.Threading.Thread.Sleep(100);
+ procs = CountProcesses();
+ }
+ if (procs > numProcessesRunning)
+ {
+ KillOrphanedConnections();
+ int temp = CountProcesses();
+ Assert.AreEqual(numProcessesRunning, temp, "Killing orphaned connections failed");
+ Assert.AreEqual(numProcessesRunning, procs, "Too many processes still running");
+ }
+ }
+
+ private void KillOrphanedConnections()
+ {
+ MySqlDataAdapter da = new MySqlDataAdapter("SHOW PROCESSLIST", rootConn);
+ DataTable dt = new DataTable();
+ da.Fill(dt);
+ foreach (DataRow row in dt.Rows)
+ {
+ long id = (long)row[0];
+ if (id == rootConn.ServerThread) continue;
+ if (id == conn.ServerThread) continue;
+ suExecSQL(String.Format("KILL {0}", id));
+ }
+ }
+
+ [TearDown]
+ public virtual void Teardown()
+ {
+ CheckOrphanedConnections();
+
+ conn.Close();
+ if (Version.Major < 5)
+ suExecSQL("REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'test'");
+ else
+ suExecSQL("DROP USER 'test'@'localhost'");
+
+ DropDatabase(database0);
+ DropDatabase(database1);
+ rootConn.Close();
+ }
+
+ private void DropDatabase(string name)
+ {
+ for (int i = 0; i < 5; i++)
+ {
+ try
+ {
+ suExecSQL(String.Format("DROP DATABASE IF EXISTS `{0}`", name));
+ return;
+ }
+ catch (Exception)
+ {
+ System.Threading.Thread.Sleep(1000);
+ }
+ }
+ Assert.Fail("Unable to drop database " + name);
+ }
+
+ protected void KillConnection(MySqlConnection c)
+ {
+ int threadId = c.ServerThread;
+ MySqlCommand cmd = new MySqlCommand("KILL " + threadId, conn);
+ cmd.ExecuteNonQuery();
+
+ // the kill flag might need a little prodding to do its thing
+ try
+ {
+ cmd.CommandText = "SELECT 1";
+ cmd.Connection = c;
+ cmd.ExecuteNonQuery();
+ }
+ catch (Exception) { }
+
+ // now wait till the process dies
+ bool processStillAlive = false;
+ while (true)
+ {
+ MySqlDataAdapter da = new MySqlDataAdapter("SHOW PROCESSLIST", conn);
+ DataTable dt = new DataTable();
+ da.Fill(dt);
+ foreach (DataRow row in dt.Rows)
+ if (row["Id"].Equals(threadId))
+ processStillAlive = true;
+ if (!processStillAlive) break;
+ System.Threading.Thread.Sleep(500);
+ }
+ }
+
+ protected void KillPooledConnection(string connStr)
+ {
+ MySqlConnection c = new MySqlConnection(connStr);
+ c.Open();
+ KillConnection(c);
+ }
+
+ protected void createTable(string sql, string engine)
+ {
+ if (Version >= new Version(4,1))
+ sql += " ENGINE=" + engine;
+ else
+ sql += " TYPE=" + engine;
+ execSQL(sql);
+ }
+
+ protected void suExecSQL(string sql)
+ {
+ Debug.Assert(rootConn != null);
+ MySqlCommand cmd = new MySqlCommand(sql, rootConn);
+ cmd.ExecuteNonQuery();
+ }
+
+ protected void execSQL(string sql)
+ {
+ MySqlCommand cmd = new MySqlCommand(sql, conn);
+ cmd.ExecuteNonQuery();
+ }
+
+ protected IDataReader execReader(string sql)
+ {
+ MySqlCommand cmd = new MySqlCommand(sql, conn);
+ return cmd.ExecuteReader();
+ }
+
+ protected int CountProcesses()
+ {
+ MySqlDataAdapter da = new MySqlDataAdapter("SHOW PROCESSLIST", rootConn);
+ DataTable dt = new DataTable();
+ da.Fill(dt);
+ return dt.Rows.Count;
+ }
+
+ protected bool TableExists(string tableName)
+ {
+ string[] restrictions = new string[4];
+ restrictions[2] = tableName;
+ DataTable dt = conn.GetSchema("Tables", restrictions);
+ return dt.Rows.Count > 0;
+ }
+
+ protected DataTable FillTable(string sql)
+ {
+ MySqlDataAdapter da = new MySqlDataAdapter(sql, conn);
+ DataTable dt = new DataTable();
+ da.Fill(dt);
+ return dt;
+ }
+ }
}
=== modified file 'Tests/MySql.Data.Tests/BlobTests.cs'
--- a/Tests/MySql.Data.Tests/BlobTests.cs 2011-06-21 18:51:27 +0000
+++ b/Tests/MySql.Data.Tests/BlobTests.cs 2011-06-23 15:01:13 +0000
@@ -37,12 +37,12 @@
[Test]
public void InsertBinary()
{
- int lenIn = 400000;
+ int lenIn = 400000;
byte[] dataIn = Utils.CreateBlob(lenIn);
- execSQL("CREATE TABLE Test (id INT NOT NULL, blob1 LONGBLOB, PRIMARY KEY(id))");
+ execSQL("CREATE TABLE Test (id INT NOT NULL, blob1 LONGBLOB, PRIMARY KEY(id))");
- MySqlCommand cmd = new MySqlCommand("INSERT INTO Test VALUES (?id, ?b1)", conn);
+ MySqlCommand cmd = new MySqlCommand("INSERT INTO Test VALUES (?id, ?b1)", conn);
cmd.Parameters.Add(new MySqlParameter("?id", 1));
cmd.Parameters.Add(new MySqlParameter("?b1", dataIn));
int rows = cmd.ExecuteNonQuery();
@@ -55,43 +55,43 @@
Assert.AreEqual(2, rows, "Checking insert rowcount");
cmd.CommandText = "SELECT * FROM Test";
- using (MySqlDataReader reader = cmd.ExecuteReader())
- {
- Assert.AreEqual(true, reader.HasRows, "Checking HasRows");
-
- reader.Read();
-
- byte[] dataOut = new byte[lenIn];
- long lenOut = reader.GetBytes(1, 0, dataOut, 0, lenIn);
-
- Assert.AreEqual(lenIn, lenOut, "Checking length of binary data (row 1)");
-
- // now see if the buffer is intact
- for (int x = 0; x < dataIn.Length; x++)
- Assert.AreEqual(dataIn[x], dataOut[x], "Checking first binary array at " + x);
-
- // now we test chunking
- int pos = 0;
- int lenToRead = dataIn.Length;
- while (lenToRead > 0)
- {
- int size = Math.Min(lenToRead, 1024);
- int read = (int)reader.GetBytes(1, pos, dataOut, pos, size);
- lenToRead -= read;
- pos += read;
- }
- // now see if the buffer is intact
- for (int x = 0; x < dataIn.Length; x++)
- Assert.AreEqual(dataIn[x], dataOut[x], "Checking first binary array at " + x);
-
- reader.Read();
- lenOut = reader.GetBytes(1, 0, dataOut, 0, lenIn);
- Assert.AreEqual(lenIn, lenOut, "Checking length of binary data (row 2)");
-
- // now see if the buffer is intact
- for (int x = 0; x < dataIn2.Length; x++)
- Assert.AreEqual(dataIn2[x], dataOut[x], "Checking second binary array at " + x);
- }
+ using (MySqlDataReader reader = cmd.ExecuteReader())
+ {
+ Assert.AreEqual(true, reader.HasRows, "Checking HasRows");
+
+ reader.Read();
+
+ byte[] dataOut = new byte[lenIn];
+ long lenOut = reader.GetBytes(1, 0, dataOut, 0, lenIn);
+
+ Assert.AreEqual(lenIn, lenOut, "Checking length of binary data (row 1)");
+
+ // now see if the buffer is intact
+ for (int x = 0; x < dataIn.Length; x++)
+ Assert.AreEqual(dataIn[x], dataOut[x], "Checking first binary array at " + x);
+
+ // now we test chunking
+ int pos = 0;
+ int lenToRead = dataIn.Length;
+ while (lenToRead > 0)
+ {
+ int size = Math.Min(lenToRead, 1024);
+ int read = (int)reader.GetBytes(1, pos, dataOut, pos, size);
+ lenToRead -= read;
+ pos += read;
+ }
+ // now see if the buffer is intact
+ for (int x = 0; x < dataIn.Length; x++)
+ Assert.AreEqual(dataIn[x], dataOut[x], "Checking first binary array at " + x);
+
+ reader.Read();
+ lenOut = reader.GetBytes(1, 0, dataOut, 0, lenIn);
+ Assert.AreEqual(lenIn, lenOut, "Checking length of binary data (row 2)");
+
+ // now see if the buffer is intact
+ for (int x = 0; x < dataIn2.Length; x++)
+ Assert.AreEqual(dataIn2[x], dataOut[x], "Checking second binary array at " + x);
+ }
}
[Test]
@@ -103,16 +103,16 @@
[Test]
public void GetCharsPrepared()
{
- if (Version < new Version(4, 1)) return;
+ if (Version < new Version(4, 1)) return;
- InternalGetChars(true);
+ InternalGetChars(true);
}
private void InternalGetChars(bool prepare)
{
- execSQL("CREATE TABLE Test (id INT NOT NULL, text1 LONGTEXT, PRIMARY KEY(id))");
+ execSQL("CREATE TABLE Test (id INT NOT NULL, text1 LONGTEXT, PRIMARY KEY(id))");
- char[] data = new char[20000];
+ char[] data = new char[20000];
for (int x = 0; x < data.Length; x++)
data[x] = (char)(65 + (x % 20));
@@ -127,25 +127,25 @@
if (prepare)
cmd.Prepare();
- using (MySqlDataReader reader = cmd.ExecuteReader())
- {
- reader.Read();
+ using (MySqlDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
- // now we test chunking
- char[] dataOut = new char[data.Length];
- int pos = 0;
- int lenToRead = data.Length;
- while (lenToRead > 0)
- {
- int size = Math.Min(lenToRead, 1024);
- int read = (int)reader.GetChars(1, pos, dataOut, pos, size);
- lenToRead -= read;
- pos += read;
- }
- // now see if the buffer is intact
- for (int x = 0; x < data.Length; x++)
- Assert.AreEqual(data[x], dataOut[x], "Checking first text array at " + x);
- }
+ // now we test chunking
+ char[] dataOut = new char[data.Length];
+ int pos = 0;
+ int lenToRead = data.Length;
+ while (lenToRead > 0)
+ {
+ int size = Math.Min(lenToRead, 1024);
+ int read = (int)reader.GetChars(1, pos, dataOut, pos, size);
+ lenToRead -= read;
+ pos += read;
+ }
+ // now see if the buffer is intact
+ for (int x = 0; x < data.Length; x++)
+ Assert.AreEqual(data[x], dataOut[x], "Checking first text array at " + x);
+ }
}
[Test]
@@ -157,16 +157,16 @@
[Test]
public void InsertTextPrepared()
{
- if (Version < new Version(4, 1)) return;
+ if (Version < new Version(4, 1)) return;
- InternalInsertText(true);
+ InternalInsertText(true);
}
private void InternalInsertText(bool prepare)
{
- execSQL("CREATE TABLE Test (id INT NOT NULL, blob1 LONGBLOB, text1 LONGTEXT, PRIMARY KEY(id))");
+ execSQL("CREATE TABLE Test (id INT NOT NULL, blob1 LONGBLOB, text1 LONGTEXT, PRIMARY KEY(id))");
- byte[] data = new byte[1024];
+ byte[] data = new byte[1024];
for (int x = 0; x < 1024; x++)
data[x] = (byte)(65 + (x % 20));
@@ -189,8 +189,8 @@
cmd.CommandText = "SELECT * FROM Test";
if (prepare) cmd.Prepare();
- using (MySqlDataReader reader = cmd.ExecuteReader())
- {
+ using (MySqlDataReader reader = cmd.ExecuteReader())
+ {
Assert.AreEqual(true, reader.HasRows, "Checking HasRows");
Assert.IsTrue(reader.Read());
@@ -230,7 +230,7 @@
dt.Clear();
da.Fill(dt);
- cb.Dispose();
+ cb.Dispose();
byte[] outBuf = (byte[])dt.Rows[0]["blob1"];
Assert.AreEqual(inBuf.Length, outBuf.Length,
@@ -242,19 +242,19 @@
[Test]
public void GetCharsOnLongTextColumn()
{
- execSQL("CREATE TABLE Test (id INT NOT NULL, blob1 LONGBLOB, text1 LONGTEXT, PRIMARY KEY(id))");
- execSQL("INSERT INTO Test (id, text1) VALUES(1, 'Test')");
+ execSQL("CREATE TABLE Test (id INT NOT NULL, blob1 LONGBLOB, text1 LONGTEXT, PRIMARY KEY(id))");
+ execSQL("INSERT INTO Test (id, text1) VALUES(1, 'Test')");
MySqlCommand cmd = new MySqlCommand("SELECT id, text1 FROM Test", conn);
char[] buf = new char[2];
- using (MySqlDataReader reader = cmd.ExecuteReader())
- {
- reader.Read();
- reader.GetChars(1, 0, buf, 0, 2);
- Assert.AreEqual('T', buf[0]);
- Assert.AreEqual('e', buf[1]);
- }
+ using (MySqlDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ reader.GetChars(1, 0, buf, 0, 2);
+ Assert.AreEqual('T', buf[0]);
+ Assert.AreEqual('e', buf[1]);
+ }
}
[Test]
@@ -276,7 +276,7 @@
cmd.Parameters.AddWithValue("?id", 1);
cmd.Prepare();
- using (MySqlDataReader reader = cmd.ExecuteReader())
+ using (MySqlDataReader reader = cmd.ExecuteReader())
{
reader.Read();
uint actualsize = reader.GetUInt32(1);
@@ -292,24 +292,25 @@
[Test]
public void BlobBiggerThanMaxPacket()
{
- suExecSQL("SET GLOBAL max_allowed_packet=500000");
+ int size = 500 * 1024;
+ suExecSQL("SET GLOBAL max_allowed_packet=" + size);
execSQL("CREATE TABLE test (id INT(10), image BLOB)");
using (MySqlConnection c = new MySqlConnection(GetConnectionString(true)))
- {
+ {
c.Open();
- byte[] image = Utils.CreateBlob(1000000);
+ byte[] image = Utils.CreateBlob(1000000);
- MySqlCommand cmd = new MySqlCommand("INSERT INTO test VALUES(NULL, ?image)", c);
+ MySqlCommand cmd = new MySqlCommand("INSERT INTO test VALUES(NULL, ?image)", c);
cmd.Parameters.AddWithValue("?image", image);
- try
- {
- cmd.ExecuteNonQuery();
- Assert.Fail("This should have thrown an exception");
- }
- catch (MySqlException)
- {
- }
+ try
+ {
+ cmd.ExecuteNonQuery();
+ Assert.Fail("This should have thrown an exception");
+ }
+ catch (MySqlException)
+ {
+ }
}
}
}
@@ -321,7 +322,7 @@
{
protected override string GetConnectionInfo()
{
- return String.Format("port={0};compress=true", port);
+ return String.Format("port={0};compress=true", port);
}
}
@@ -330,18 +331,18 @@
{
protected override string GetConnectionInfo()
{
- return String.Format("protocol=pipe;pipe name={0}", pipeName);
+ return String.Format("protocol=pipe;pipe name={0}", pipeName);
}
}
[Category("Compressed")]
- [Category("Pipe")]
+ [Category("Pipe")]
public class BlobTestsPipeCompressed : BlobTests
{
protected override string GetConnectionInfo()
{
- return String.Format("protocol=pipe;pipe name={0};compress=true", pipeName);
- }
+ return String.Format("protocol=pipe;pipe name={0};compress=true", pipeName);
+ }
}
[Category("SharedMemory")]
@@ -349,18 +350,18 @@
{
protected override string GetConnectionInfo()
{
- return String.Format("protocol=memory; shared memory name={0}", memoryName);
+ return String.Format("protocol=memory; shared memory name={0}", memoryName);
}
}
[Category("Compressed")]
- [Category("SharedMemory")]
+ [Category("SharedMemory")]
public class BlobTestsSharedMemoryCompressed : BlobTests
{
protected override string GetConnectionInfo()
{
- return String.Format("protocol=memory; shared memory name={0};compress=true", memoryName);
- }
+ return String.Format("protocol=memory; shared memory name={0};compress=true", memoryName);
+ }
}
#endif
#endregion
=== modified file 'Tests/MySql.Data.Tests/BulkLoading.cs'
--- a/Tests/MySql.Data.Tests/BulkLoading.cs 2011-06-21 18:51:27 +0000
+++ b/Tests/MySql.Data.Tests/BulkLoading.cs 2011-06-23 15:01:13 +0000
@@ -31,338 +31,338 @@
[TestFixture]
public class BulkLoading : BaseTest
{
- [Test]
- public void BulkLoadSimple()
- {
- execSQL("CREATE TABLE Test (id INT NOT NULL, name VARCHAR(250), PRIMARY KEY(id))");
-
- // first create the external file
- string path = Path.GetTempFileName();
- StreamWriter sw = new StreamWriter(path);
- for (int i = 0; i < 200; i++)
- sw.WriteLine(i + "\t'Test'");
- sw.Flush();
- sw.Close();
-
- MySqlBulkLoader loader = new MySqlBulkLoader(conn);
- loader.TableName = "Test";
- loader.FileName = path;
- loader.Timeout = 0;
- int count = loader.Load();
- Assert.AreEqual(200, count);
-
- MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
- DataTable dt = new DataTable();
- da.Fill(dt);
- Assert.AreEqual(200, dt.Rows.Count);
- Assert.AreEqual("'Test'", dt.Rows[0][1].ToString().Trim());
- }
-
- [Test]
- public void BulkLoadReadOnlyFile()
- {
- execSQL("CREATE TABLE Test (id INT NOT NULL, name VARCHAR(250), PRIMARY KEY(id))");
-
- // first create the external file
- string path = Path.GetTempFileName();
- StreamWriter sw = new StreamWriter(path);
- for (int i = 0; i < 200; i++)
- sw.WriteLine(i + "\t'Test'");
- sw.Flush();
- sw.Close();
-
- FileInfo fi = new FileInfo(path);
- FileAttributes oldAttr = fi.Attributes;
- fi.Attributes = fi.Attributes | FileAttributes.ReadOnly;
- try
- {
- MySqlBulkLoader loader = new MySqlBulkLoader(conn);
- loader.TableName = "Test";
- loader.FileName = path;
- loader.Timeout = 0;
- int count = loader.Load();
- Assert.AreEqual(200, count);
-
- MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
- DataTable dt = new DataTable();
- da.Fill(dt);
- Assert.AreEqual(200, dt.Rows.Count);
- Assert.AreEqual("'Test'", dt.Rows[0][1].ToString().Trim());
- }
- finally
- {
- fi.Attributes = oldAttr;
- fi.Delete();
- }
- }
-
- [Test]
- public void BulkLoadSimple2()
- {
- execSQL("CREATE TABLE Test (id INT NOT NULL, name VARCHAR(250), PRIMARY KEY(id))");
-
- // first create the external file
- string path = Path.GetTempFileName();
- StreamWriter sw = new StreamWriter(path);
- for (int i = 0; i < 200; i++)
- sw.Write(i + ",'Test' xxx");
- sw.Flush();
- sw.Close();
-
- MySqlBulkLoader loader = new MySqlBulkLoader(conn);
- loader.TableName = "Test";
- loader.FileName = path;
- loader.Timeout = 0;
- loader.FieldTerminator = ",";
- loader.LineTerminator = "xxx";
- int count = loader.Load();
- Assert.AreEqual(200, count);
-
- MySqlCommand cmd = new MySqlCommand("SELECT COUNT(*) FROM Test", conn);
- Assert.AreEqual(200, cmd.ExecuteScalar());
- }
-
- [Test]
- public void BulkLoadSimple3()
- {
- execSQL("CREATE TABLE Test (id INT NOT NULL, name VARCHAR(250), PRIMARY KEY(id))");
-
- // first create the external file
- string path = Path.GetTempFileName();
- StreamWriter sw = new StreamWriter(path);
- for (int i = 0; i < 200; i++)
- sw.Write(i + ",'Test' xxx");
- sw.Flush();
- sw.Close();
-
- MySqlBulkLoader loader = new MySqlBulkLoader(conn);
- loader.TableName = "Test";
- loader.FileName = path;
- loader.Timeout = 0;
- loader.FieldTerminator = ",";
- loader.LineTerminator = "xxx";
- loader.NumberOfLinesToSkip = 50;
- int count = loader.Load();
- Assert.AreEqual(150, count);
-
- MySqlCommand cmd = new MySqlCommand("SELECT COUNT(*) FROM Test", conn);
- Assert.AreEqual(150, cmd.ExecuteScalar());
- }
-
- [Test]
- public void BulkLoadSimple4()
- {
- execSQL("CREATE TABLE Test (id INT NOT NULL, name VARCHAR(250), PRIMARY KEY(id))");
-
- // first create the external file
- string path = Path.GetTempFileName();
- StreamWriter sw = new StreamWriter(path);
- for (int i = 0; i < 100; i++)
- sw.Write("aaa" + i + ",'Test' xxx");
- for (int i = 100; i < 200; i++)
- sw.Write("bbb" + i + ",'Test' xxx");
- for (int i = 200; i < 300; i++)
- sw.Write("aaa" + i + ",'Test' xxx");
- for (int i = 300; i < 400; i++)
- sw.Write("bbb" + i + ",'Test' xxx");
- sw.Flush();
- sw.Close();
-
- MySqlBulkLoader loader = new MySqlBulkLoader(conn);
- loader.TableName = "Test";
- loader.FileName = path;
- loader.Timeout = 0;
- loader.FieldTerminator = ",";
- loader.LineTerminator = "xxx";
- loader.LinePrefix = "bbb";
- int count = loader.Load();
- Assert.AreEqual(200, count);
-
- MySqlCommand cmd = new MySqlCommand("SELECT COUNT(*) FROM Test", conn);
- Assert.AreEqual(200, cmd.ExecuteScalar());
- }
-
- [Test]
- public void BulkLoadFieldQuoting()
- {
- execSQL("CREATE TABLE Test (id INT NOT NULL, name VARCHAR(250), name2 VARCHAR(250), PRIMARY KEY(id))");
-
- // first create the external file
- string path = Path.GetTempFileName();
- StreamWriter sw = new StreamWriter(path);
- for (int i = 0; i < 200; i++)
- sw.WriteLine(i + "\t`col1`\tcol2");
- sw.Flush();
- sw.Close();
-
- MySqlBulkLoader loader = new MySqlBulkLoader(conn);
- loader.TableName = "Test";
- loader.FileName = path;
- loader.Timeout = 0;
- loader.FieldQuotationCharacter = '`';
- loader.FieldQuotationOptional = true;
- int count = loader.Load();
- Assert.AreEqual(200, count);
-
- MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
- DataTable dt = new DataTable();
- da.Fill(dt);
- Assert.AreEqual(200, dt.Rows.Count);
- Assert.AreEqual("col1", dt.Rows[0][1]);
- Assert.AreEqual("col2", dt.Rows[0][2].ToString().Trim());
- }
-
- [Test]
- public void BulkLoadEscaping()
- {
- execSQL("CREATE TABLE Test (id INT NOT NULL, name VARCHAR(250), name2 VARCHAR(250), PRIMARY KEY(id))");
-
- // first create the external file
- string path = Path.GetTempFileName();
- StreamWriter sw = new StreamWriter(path);
- for (int i = 0; i < 200; i++)
- sw.WriteLine(i + ",col1\tstill col1,col2");
- sw.Flush();
- sw.Close();
-
- MySqlBulkLoader loader = new MySqlBulkLoader(conn);
- loader.TableName = "Test";
- loader.FileName = path;
- loader.Timeout = 0;
- loader.EscapeCharacter = '\t';
- loader.FieldTerminator = ",";
- int count = loader.Load();
- Assert.AreEqual(200, count);
-
- MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
- DataTable dt = new DataTable();
- da.Fill(dt);
- Assert.AreEqual(200, dt.Rows.Count);
- Assert.AreEqual("col1still col1", dt.Rows[0][1]);
- Assert.AreEqual("col2", dt.Rows[0][2].ToString().Trim());
- }
-
- [Test]
- public void BulkLoadConflictOptionReplace()
- {
- execSQL("CREATE TABLE Test (id INT NOT NULL, name VARCHAR(250), PRIMARY KEY(id))");
-
- // first create the external file
- string path = Path.GetTempFileName();
- StreamWriter sw = new StreamWriter(path);
- for (int i = 0; i < 20; i++)
- sw.WriteLine(i + ",col1");
- sw.Flush();
- sw.Close();
-
- MySqlBulkLoader loader = new MySqlBulkLoader(conn);
- loader.TableName = "Test";
- loader.FileName = path;
- loader.Timeout = 0;
- loader.FieldTerminator = ",";
- int count = loader.Load();
- Assert.AreEqual(20, count);
-
- path = Path.GetTempFileName();
- sw = new StreamWriter(path);
- for (int i = 0; i < 20; i++)
- sw.WriteLine(i + ",col2");
- sw.Flush();
- sw.Close();
-
- loader = new MySqlBulkLoader(conn);
- loader.TableName = "Test";
- loader.FileName = path;
- loader.Timeout = 0;
- loader.FieldTerminator = ",";
- loader.ConflictOption = MySqlBulkLoaderConflictOption.Replace;
- loader.Load();
-
- MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
- DataTable dt = new DataTable();
- da.Fill(dt);
- Assert.AreEqual(20, dt.Rows.Count);
- Assert.AreEqual("col2", dt.Rows[0][1].ToString().Trim());
- }
-
- [Test]
- public void BulkLoadConflictOptionIgnore()
- {
- execSQL("CREATE TABLE Test (id INT NOT NULL, name VARCHAR(250), PRIMARY KEY(id))");
-
- // first create the external file
- string path = Path.GetTempFileName();
- StreamWriter sw = new StreamWriter(path);
- for (int i = 0; i < 20; i++)
- sw.WriteLine(i + ",col1");
- sw.Flush();
- sw.Close();
-
- MySqlBulkLoader loader = new MySqlBulkLoader(conn);
- loader.TableName = "Test";
- loader.FileName = path;
- loader.Timeout = 0;
- loader.FieldTerminator = ",";
- int count = loader.Load();
- Assert.AreEqual(20, count);
-
- path = Path.GetTempFileName();
- sw = new StreamWriter(path);
- for (int i = 0; i < 20; i++)
- sw.WriteLine(i + ",col2");
- sw.Flush();
- sw.Close();
-
- loader = new MySqlBulkLoader(conn);
- loader.TableName = "Test";
- loader.FileName = path;
- loader.Timeout = 0;
- loader.FieldTerminator = ",";
- loader.ConflictOption = MySqlBulkLoaderConflictOption.Ignore;
- loader.Load();
-
- MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
- DataTable dt = new DataTable();
- da.Fill(dt);
- Assert.AreEqual(20, dt.Rows.Count);
- Assert.AreEqual("col1", dt.Rows[0][1].ToString().Trim());
- }
-
- [Test]
- public void BulkLoadColumnOrder()
- {
- execSQL(@"CREATE TABLE Test (id INT NOT NULL, n1 VARCHAR(250), n2 VARCHAR(250),
- n3 VARCHAR(250), PRIMARY KEY(id))");
-
- // first create the external file
- string path = Path.GetTempFileName();
- StreamWriter sw = new StreamWriter(path);
- for (int i = 0; i < 20; i++)
- sw.WriteLine(i + ",col3,col2,col1");
- sw.Flush();
- sw.Close();
-
- MySqlBulkLoader loader = new MySqlBulkLoader(conn);
- loader.TableName = "Test";
- loader.FileName = path;
- loader.Timeout = 0;
- loader.FieldTerminator = ",";
- loader.LineTerminator = Environment.NewLine;
- loader.Columns.Add("id");
- loader.Columns.Add("n3");
- loader.Columns.Add("n2");
- loader.Columns.Add("n1");
- int count = loader.Load();
- Assert.AreEqual(20, count);
-
- MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
- DataTable dt = new DataTable();
- da.Fill(dt);
- Assert.AreEqual(20, dt.Rows.Count);
- Assert.AreEqual("col1", dt.Rows[0][1]);
- Assert.AreEqual("col2", dt.Rows[0][2]);
- Assert.AreEqual("col3", dt.Rows[0][3].ToString().Trim());
- }
-
- }
+ [Test]
+ public void BulkLoadSimple()
+ {
+ execSQL("CREATE TABLE Test (id INT NOT NULL, name VARCHAR(250), PRIMARY KEY(id))");
+
+ // first create the external file
+ string path = Path.GetTempFileName();
+ StreamWriter sw = new StreamWriter(path);
+ for (int i = 0; i < 200; i++)
+ sw.WriteLine(i + "\t'Test'");
+ sw.Flush();
+ sw.Close();
+
+ MySqlBulkLoader loader = new MySqlBulkLoader(conn);
+ loader.TableName = "Test";
+ loader.FileName = path;
+ loader.Timeout = 0;
+ int count = loader.Load();
+ Assert.AreEqual(200, count);
+
+ MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
+ DataTable dt = new DataTable();
+ da.Fill(dt);
+ Assert.AreEqual(200, dt.Rows.Count);
+ Assert.AreEqual("'Test'", dt.Rows[0][1].ToString().Trim());
+ }
+
+ [Test]
+ public void BulkLoadReadOnlyFile()
+ {
+ execSQL("CREATE TABLE Test (id INT NOT NULL, name VARCHAR(250), PRIMARY KEY(id))");
+
+ // first create the external file
+ string path = Path.GetTempFileName();
+ StreamWriter sw = new StreamWriter(path);
+ for (int i = 0; i < 200; i++)
+ sw.WriteLine(i + "\t'Test'");
+ sw.Flush();
+ sw.Close();
+
+ FileInfo fi = new FileInfo(path);
+ FileAttributes oldAttr = fi.Attributes;
+ fi.Attributes = fi.Attributes | FileAttributes.ReadOnly;
+ try
+ {
+ MySqlBulkLoader loader = new MySqlBulkLoader(conn);
+ loader.TableName = "Test";
+ loader.FileName = path;
+ loader.Timeout = 0;
+ int count = loader.Load();
+ Assert.AreEqual(200, count);
+
+ MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
+ DataTable dt = new DataTable();
+ da.Fill(dt);
+ Assert.AreEqual(200, dt.Rows.Count);
+ Assert.AreEqual("'Test'", dt.Rows[0][1].ToString().Trim());
+ }
+ finally
+ {
+ fi.Attributes = oldAttr;
+ fi.Delete();
+ }
+ }
+
+ [Test]
+ public void BulkLoadSimple2()
+ {
+ execSQL("CREATE TABLE Test (id INT NOT NULL, name VARCHAR(250), PRIMARY KEY(id))");
+
+ // first create the external file
+ string path = Path.GetTempFileName();
+ StreamWriter sw = new StreamWriter(path);
+ for (int i = 0; i < 200; i++)
+ sw.Write(i + ",'Test' xxx");
+ sw.Flush();
+ sw.Close();
+
+ MySqlBulkLoader loader = new MySqlBulkLoader(conn);
+ loader.TableName = "Test";
+ loader.FileName = path;
+ loader.Timeout = 0;
+ loader.FieldTerminator = ",";
+ loader.LineTerminator = "xxx";
+ int count = loader.Load();
+ Assert.AreEqual(200, count);
+
+ MySqlCommand cmd = new MySqlCommand("SELECT COUNT(*) FROM Test", conn);
+ Assert.AreEqual(200, cmd.ExecuteScalar());
+ }
+
+ [Test]
+ public void BulkLoadSimple3()
+ {
+ execSQL("CREATE TABLE Test (id INT NOT NULL, name VARCHAR(250), PRIMARY KEY(id))");
+
+ // first create the external file
+ string path = Path.GetTempFileName();
+ StreamWriter sw = new StreamWriter(path);
+ for (int i = 0; i < 200; i++)
+ sw.Write(i + ",'Test' xxx");
+ sw.Flush();
+ sw.Close();
+
+ MySqlBulkLoader loader = new MySqlBulkLoader(conn);
+ loader.TableName = "Test";
+ loader.FileName = path;
+ loader.Timeout = 0;
+ loader.FieldTerminator = ",";
+ loader.LineTerminator = "xxx";
+ loader.NumberOfLinesToSkip = 50;
+ int count = loader.Load();
+ Assert.AreEqual(150, count);
+
+ MySqlCommand cmd = new MySqlCommand("SELECT COUNT(*) FROM Test", conn);
+ Assert.AreEqual(150, cmd.ExecuteScalar());
+ }
+
+ [Test]
+ public void BulkLoadSimple4()
+ {
+ execSQL("CREATE TABLE Test (id INT NOT NULL, name VARCHAR(250), PRIMARY KEY(id))");
+
+ // first create the external file
+ string path = Path.GetTempFileName();
+ StreamWriter sw = new StreamWriter(path);
+ for (int i = 0; i < 100; i++)
+ sw.Write("aaa" + i + ",'Test' xxx");
+ for (int i = 100; i < 200; i++)
+ sw.Write("bbb" + i + ",'Test' xxx");
+ for (int i = 200; i < 300; i++)
+ sw.Write("aaa" + i + ",'Test' xxx");
+ for (int i = 300; i < 400; i++)
+ sw.Write("bbb" + i + ",'Test' xxx");
+ sw.Flush();
+ sw.Close();
+
+ MySqlBulkLoader loader = new MySqlBulkLoader(conn);
+ loader.TableName = "Test";
+ loader.FileName = path;
+ loader.Timeout = 0;
+ loader.FieldTerminator = ",";
+ loader.LineTerminator = "xxx";
+ loader.LinePrefix = "bbb";
+ int count = loader.Load();
+ Assert.AreEqual(200, count);
+
+ MySqlCommand cmd = new MySqlCommand("SELECT COUNT(*) FROM Test", conn);
+ Assert.AreEqual(200, cmd.ExecuteScalar());
+ }
+
+ [Test]
+ public void BulkLoadFieldQuoting()
+ {
+ execSQL("CREATE TABLE Test (id INT NOT NULL, name VARCHAR(250), name2 VARCHAR(250), PRIMARY KEY(id))");
+
+ // first create the external file
+ string path = Path.GetTempFileName();
+ StreamWriter sw = new StreamWriter(path);
+ for (int i = 0; i < 200; i++)
+ sw.WriteLine(i + "\t`col1`\tcol2");
+ sw.Flush();
+ sw.Close();
+
+ MySqlBulkLoader loader = new MySqlBulkLoader(conn);
+ loader.TableName = "Test";
+ loader.FileName = path;
+ loader.Timeout = 0;
+ loader.FieldQuotationCharacter = '`';
+ loader.FieldQuotationOptional = true;
+ int count = loader.Load();
+ Assert.AreEqual(200, count);
+
+ MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
+ DataTable dt = new DataTable();
+ da.Fill(dt);
+ Assert.AreEqual(200, dt.Rows.Count);
+ Assert.AreEqual("col1", dt.Rows[0][1]);
+ Assert.AreEqual("col2", dt.Rows[0][2].ToString().Trim());
+ }
+
+ [Test]
+ public void BulkLoadEscaping()
+ {
+ execSQL("CREATE TABLE Test (id INT NOT NULL, name VARCHAR(250), name2 VARCHAR(250), PRIMARY KEY(id))");
+
+ // first create the external file
+ string path = Path.GetTempFileName();
+ StreamWriter sw = new StreamWriter(path);
+ for (int i = 0; i < 200; i++)
+ sw.WriteLine(i + ",col1\tstill col1,col2");
+ sw.Flush();
+ sw.Close();
+
+ MySqlBulkLoader loader = new MySqlBulkLoader(conn);
+ loader.TableName = "Test";
+ loader.FileName = path;
+ loader.Timeout = 0;
+ loader.EscapeCharacter = '\t';
+ loader.FieldTerminator = ",";
+ int count = loader.Load();
+ Assert.AreEqual(200, count);
+
+ MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
+ DataTable dt = new DataTable();
+ da.Fill(dt);
+ Assert.AreEqual(200, dt.Rows.Count);
+ Assert.AreEqual("col1still col1", dt.Rows[0][1]);
+ Assert.AreEqual("col2", dt.Rows[0][2].ToString().Trim());
+ }
+
+ [Test]
+ public void BulkLoadConflictOptionReplace()
+ {
+ execSQL("CREATE TABLE Test (id INT NOT NULL, name VARCHAR(250), PRIMARY KEY(id))");
+
+ // first create the external file
+ string path = Path.GetTempFileName();
+ StreamWriter sw = new StreamWriter(path);
+ for (int i = 0; i < 20; i++)
+ sw.WriteLine(i + ",col1");
+ sw.Flush();
+ sw.Close();
+
+ MySqlBulkLoader loader = new MySqlBulkLoader(conn);
+ loader.TableName = "Test";
+ loader.FileName = path;
+ loader.Timeout = 0;
+ loader.FieldTerminator = ",";
+ int count = loader.Load();
+ Assert.AreEqual(20, count);
+
+ path = Path.GetTempFileName();
+ sw = new StreamWriter(path);
+ for (int i = 0; i < 20; i++)
+ sw.WriteLine(i + ",col2");
+ sw.Flush();
+ sw.Close();
+
+ loader = new MySqlBulkLoader(conn);
+ loader.TableName = "Test";
+ loader.FileName = path;
+ loader.Timeout = 0;
+ loader.FieldTerminator = ",";
+ loader.ConflictOption = MySqlBulkLoaderConflictOption.Replace;
+ loader.Load();
+
+ MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
+ DataTable dt = new DataTable();
+ da.Fill(dt);
+ Assert.AreEqual(20, dt.Rows.Count);
+ Assert.AreEqual("col2", dt.Rows[0][1].ToString().Trim());
+ }
+
+ [Test]
+ public void BulkLoadConflictOptionIgnore()
+ {
+ execSQL("CREATE TABLE Test (id INT NOT NULL, name VARCHAR(250), PRIMARY KEY(id))");
+
+ // first create the external file
+ string path = Path.GetTempFileName();
+ StreamWriter sw = new StreamWriter(path);
+ for (int i = 0; i < 20; i++)
+ sw.WriteLine(i + ",col1");
+ sw.Flush();
+ sw.Close();
+
+ MySqlBulkLoader loader = new MySqlBulkLoader(conn);
+ loader.TableName = "Test";
+ loader.FileName = path;
+ loader.Timeout = 0;
+ loader.FieldTerminator = ",";
+ int count = loader.Load();
+ Assert.AreEqual(20, count);
+
+ path = Path.GetTempFileName();
+ sw = new StreamWriter(path);
+ for (int i = 0; i < 20; i++)
+ sw.WriteLine(i + ",col2");
+ sw.Flush();
+ sw.Close();
+
+ loader = new MySqlBulkLoader(conn);
+ loader.TableName = "Test";
+ loader.FileName = path;
+ loader.Timeout = 0;
+ loader.FieldTerminator = ",";
+ loader.ConflictOption = MySqlBulkLoaderConflictOption.Ignore;
+ loader.Load();
+
+ MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
+ DataTable dt = new DataTable();
+ da.Fill(dt);
+ Assert.AreEqual(20, dt.Rows.Count);
+ Assert.AreEqual("col1", dt.Rows[0][1].ToString().Trim());
+ }
+
+ [Test]
+ public void BulkLoadColumnOrder()
+ {
+ execSQL(@"CREATE TABLE Test (id INT NOT NULL, n1 VARCHAR(250), n2 VARCHAR(250),
+ n3 VARCHAR(250), PRIMARY KEY(id))");
+
+ // first create the external file
+ string path = Path.GetTempFileName();
+ StreamWriter sw = new StreamWriter(path);
+ for (int i = 0; i < 20; i++)
+ sw.WriteLine(i + ",col3,col2,col1");
+ sw.Flush();
+ sw.Close();
+
+ MySqlBulkLoader loader = new MySqlBulkLoader(conn);
+ loader.TableName = "Test";
+ loader.FileName = path;
+ loader.Timeout = 0;
+ loader.FieldTerminator = ",";
+ loader.LineTerminator = Environment.NewLine;
+ loader.Columns.Add("id");
+ loader.Columns.Add("n3");
+ loader.Columns.Add("n2");
+ loader.Columns.Add("n1");
+ int count = loader.Load();
+ Assert.AreEqual(20, count);
+
+ MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
+ DataTable dt = new DataTable();
+ da.Fill(dt);
+ Assert.AreEqual(20, dt.Rows.Count);
+ Assert.AreEqual("col1", dt.Rows[0][1]);
+ Assert.AreEqual("col2", dt.Rows[0][2]);
+ Assert.AreEqual("col3", dt.Rows[0][3].ToString().Trim());
+ }
+
+ }
}
=== modified file 'Tests/MySql.Data.Tests/CharacterSetTests.cs'
Binary files a/Tests/MySql.Data.Tests/CharacterSetTests.cs 2011-06-21 18:51:27 +0000 and b/Tests/MySql.Data.Tests/CharacterSetTests.cs 2011-06-23 15:01:13 +0000 differ
=== modified file 'Tests/MySql.Data.Tests/CommandBuilderTests.cs'
--- a/Tests/MySql.Data.Tests/CommandBuilderTests.cs 2011-06-21 18:51:27 +0000
+++ b/Tests/MySql.Data.Tests/CommandBuilderTests.cs 2011-06-23 15:01:13 +0000
@@ -29,10 +29,6 @@
[TestFixture]
public class CommandBuilderTests : BaseTest
{
- public CommandBuilderTests()
- {
- }
-
[Test]
public void MultiWord()
{
=== modified file 'Tests/MySql.Data.Tests/CommandTests.cs'
--- a/Tests/MySql.Data.Tests/CommandTests.cs 2011-06-21 18:51:27 +0000
+++ b/Tests/MySql.Data.Tests/CommandTests.cs 2011-06-23 15:01:13 +0000
@@ -35,8 +35,8 @@
[Test]
public void InsertTest()
{
- execSQL("CREATE TABLE Test (id int NOT NULL, name VARCHAR(100))");
- // do the insert
+ execSQL("CREATE TABLE Test (id int NOT NULL, name VARCHAR(100))");
+ // do the insert
MySqlCommand cmd = new MySqlCommand("INSERT INTO Test (id,name) VALUES(10,'Test')", conn);
int cnt = cmd.ExecuteNonQuery();
Assert.AreEqual( 1, cnt, "Insert Count" );
@@ -63,8 +63,8 @@
[Test]
public void UpdateTest()
{
- execSQL("CREATE TABLE Test (id int NOT NULL, name VARCHAR(100))");
- execSQL("INSERT INTO Test (id,name) VALUES(10, 'Test')");
+ execSQL("CREATE TABLE Test (id int NOT NULL, name VARCHAR(100))");
+ execSQL("INSERT INTO Test (id,name) VALUES(10, 'Test')");
execSQL("INSERT INTO Test (id,name) VALUES(11, 'Test2')");
// do the update
@@ -100,7 +100,7 @@
[Test]
public void DeleteTest()
{
- execSQL("CREATE TABLE Test (id int NOT NULL, name VARCHAR(100))");
+ execSQL("CREATE TABLE Test (id int NOT NULL, name VARCHAR(100))");
execSQL("INSERT INTO Test (id, name) VALUES(1, 'Test')");
execSQL("INSERT INTO Test (id, name) VALUES(2, 'Test2')");
@@ -118,22 +118,22 @@
[Test]
public void CtorTest()
{
- execSQL("CREATE TABLE Test (id int NOT NULL, name VARCHAR(100))");
- MySqlTransaction txn = conn.BeginTransaction();
+ execSQL("CREATE TABLE Test (id int NOT NULL, name VARCHAR(100))");
+ MySqlTransaction txn = conn.BeginTransaction();
MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", conn);
- MySqlCommand clone = new MySqlCommand(cmd.CommandText, (MySqlConnection)cmd.Connection,
- (MySqlTransaction)cmd.Transaction);
- clone.Parameters.AddWithValue("?test", 1);
- txn.Rollback();
- }
+ MySqlCommand clone = new MySqlCommand(cmd.CommandText, (MySqlConnection)cmd.Connection,
+ (MySqlTransaction)cmd.Transaction);
+ clone.Parameters.AddWithValue("?test", 1);
+ txn.Rollback();
+ }
[Test]
public void CloneCommand()
{
MySqlCommand cmd = new MySqlCommand();
- MySqlCommand newCommand = cmd.Clone();
- IDbCommand newCommand2 = (IDbCommand)(cmd as ICloneable).Clone();
+ MySqlCommand newCommand = cmd.Clone();
+ IDbCommand newCommand2 = (IDbCommand)(cmd as ICloneable).Clone();
}
[Test]
@@ -189,10 +189,10 @@
[Test]
public void InsertingPreparedNulls()
{
- if (Version < new Version(4, 1)) return;
+ if (Version < new Version(4, 1)) return;
- execSQL("CREATE TABLE Test (id int NOT NULL, name VARCHAR(100))");
- MySqlCommand cmd = new MySqlCommand("INSERT INTO Test VALUES(1, ?str)", conn);
+ execSQL("CREATE TABLE Test (id int NOT NULL, name VARCHAR(100))");
+ MySqlCommand cmd = new MySqlCommand("INSERT INTO Test VALUES(1, ?str)", conn);
cmd.Parameters.Add("?str", MySqlDbType.VarChar);
cmd.Prepare();
@@ -200,11 +200,11 @@
cmd.ExecuteNonQuery();
cmd.CommandText = "SELECT * FROM Test";
- using (MySqlDataReader reader = cmd.ExecuteReader())
- {
- Assert.IsTrue(reader.Read());
- Assert.AreEqual(DBNull.Value, reader[1]);
- }
+ using (MySqlDataReader reader = cmd.ExecuteReader())
+ {
+ Assert.IsTrue(reader.Read());
+ Assert.AreEqual(DBNull.Value, reader[1]);
+ }
}
/// <summary>
@@ -213,14 +213,14 @@
[Test]
public void PreparedInsertUsingReader()
{
- if (Version < new Version(4, 1)) return;
+ if (Version < new Version(4, 1)) return;
- execSQL("CREATE TABLE Test (id int NOT NULL, name VARCHAR(100))");
- MySqlCommand cmd = new MySqlCommand("INSERT INTO Test VALUES(1, 'Test')", conn);
+ execSQL("CREATE TABLE Test (id int NOT NULL, name VARCHAR(100))");
+ MySqlCommand cmd = new MySqlCommand("INSERT INTO Test VALUES(1, 'Test')", conn);
cmd.Prepare();
- using (MySqlDataReader reader = cmd.ExecuteReader())
- {
- }
+ using (MySqlDataReader reader = cmd.ExecuteReader())
+ {
+ }
cmd.CommandText = "SELECT * FROM Test";
using (MySqlDataReader reader = cmd.ExecuteReader())
@@ -231,408 +231,408 @@
}
}
- /// <summary>
- /// Bug# 8119. Unable to reproduce but left in anyway
- /// </summary>
+ /// <summary>
+ /// Bug# 8119. Unable to reproduce but left in anyway
+ /// </summary>
/* [Test]
- public void ReallyBigCommandString()
- {
- System.Text.StringBuilder sql = new System.Text.StringBuilder();
-
- for (int i = 0; i < 10; i++)
- sql.Append("DROP TABLE IF EXISTS idx" + i + ";CREATE TABLE idx" + i + "(aa int not null auto_increment primary key, a int, b varchar(50), c int);");
-
- int c = 0;
- for (int z = 0; z < 100; z++)
- for (int x = 0; x < 10; x++, c++)
- {
- string s = String.Format("INSERT INTO idx{0} (a, b, c) values ({1}, 'field{1}', {2});",
- x, z, c);
- sql.Append(s);
- }
-
- MySqlCommand cmd = new MySqlCommand(sql.ToString(), conn);
- cmd.ExecuteNonQuery();
-
- for (int i = 0; i < 10; i++)
- {
- cmd.CommandText = "SELECT COUNT(*) FROM idx" + i;
- object count = cmd.ExecuteScalar();
- Assert.AreEqual(100, count);
- execSQL("DROP TABLE IF EXISTS idx" + i);
- }
- }
+ public void ReallyBigCommandString()
+ {
+ System.Text.StringBuilder sql = new System.Text.StringBuilder();
+
+ for (int i = 0; i < 10; i++)
+ sql.Append("DROP TABLE IF EXISTS idx" + i + ";CREATE TABLE idx" + i + "(aa int not null auto_increment primary key, a int, b varchar(50), c int);");
+
+ int c = 0;
+ for (int z = 0; z < 100; z++)
+ for (int x = 0; x < 10; x++, c++)
+ {
+ string s = String.Format("INSERT INTO idx{0} (a, b, c) values ({1}, 'field{1}', {2});",
+ x, z, c);
+ sql.Append(s);
+ }
+
+ MySqlCommand cmd = new MySqlCommand(sql.ToString(), conn);
+ cmd.ExecuteNonQuery();
+
+ for (int i = 0; i < 10; i++)
+ {
+ cmd.CommandText = "SELECT COUNT(*) FROM idx" + i;
+ object count = cmd.ExecuteScalar();
+ Assert.AreEqual(100, count);
+ execSQL("DROP TABLE IF EXISTS idx" + i);
+ }
+ }
*/
- /// <summary>
- /// Bug #7248 There is already an open DataReader associated with this Connection which must
- /// </summary>
- [Test]
- public void GenWarnings()
- {
- execSQL("CREATE TABLE Test (id INT, dt DATETIME)");
- execSQL("INSERT INTO Test VALUES (1, NOW())");
- execSQL("INSERT INTO Test VALUES (2, NOW())");
- execSQL("INSERT INTO Test VALUES (3, NOW())");
-
- MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test WHERE dt = '" +
- DateTime.Now + "'", conn);
- DataSet ds = new DataSet();
- da.Fill(ds);
- }
-
- /// <summary>
- /// Bug #11991 ExecuteScalar
- /// </summary>
- [Test]
- public void CloseReaderAfterFailedConvert()
- {
- execSQL("CREATE TABLE Test (dt DATETIME)");
- execSQL("INSERT INTO Test VALUES ('00-00-0000 00:00:00')");
-
- MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", conn);
- try
- {
- cmd.ExecuteScalar();
- }
- catch (Exception)
- {
- }
-
- conn.BeginTransaction();
- }
-
- /// <summary>
- /// Bug #25443 ExecuteScalar() hangs when more than one bad result
- /// </summary>
- [Test]
- public void ExecuteWithOneBadQuery()
- {
- MySqlCommand command = new MySqlCommand("SELECT 1; SELECT * FROM foo", conn);
- try
- {
- command.ExecuteScalar();
- }
- catch (MySqlException)
- {
- }
-
- // now try using ExecuteNonQuery
- try
- {
- command.ExecuteNonQuery();
- }
- catch (MySqlException)
- {
- }
- }
-
- /// <summary>
- /// Bug #27958 Cannot use Data Source Configuration Wizard on large databases
- /// </summary>
- [Test]
- public void DefaultCommandTimeout()
- {
- MySqlConnection c = new MySqlConnection("server=localhost");
- MySqlCommand cmd = new MySqlCommand("", c);
- Assert.AreEqual(30, cmd.CommandTimeout);
-
- c = new MySqlConnection("server=localhost;default command timeout=47");
- cmd = new MySqlCommand("", c);
- Assert.AreEqual(47, cmd.CommandTimeout);
-
- cmd = new MySqlCommand("");
- Assert.AreEqual(30, cmd.CommandTimeout);
-
- cmd.CommandTimeout = 66;
- cmd.Connection = c;
- Assert.AreEqual(66, cmd.CommandTimeout);
- cmd.CommandTimeout = 0;
- Assert.AreEqual(0, cmd.CommandTimeout);
-
- c = new MySqlConnection("server=localhost;default command timeout=0");
- cmd = new MySqlCommand("", c);
- Assert.AreEqual(0, cmd.CommandTimeout);
- }
-
- /// <summary>
- /// Bug #38276 Short circuit evaluation error in MySqlCommand.CheckState()
- /// </summary>
- [Test]
- public void SetNullConnection()
- {
- MySqlCommand command = new MySqlCommand();
- command.CommandText = "SELECT 1";
- command.Connection = null;
- try
- {
- object o = command.ExecuteScalar();
- }
- catch (InvalidOperationException)
- {
- }
- }
-
- /// <summary>
- /// Bug #45941 SQL-Injection attack
- /// </summary>
- [Test]
- public void SqlInjection1()
- {
- execSQL("DROP TABLE IF EXISTS Test");
- execSQL("CREATE TABLE Test(name VARCHAR(100)) ENGINE=MyISAM DEFAULT CHARSET=utf8");
- execSQL("INSERT INTO Test VALUES ('name1'), ('name2'), ('name3')");
-
- MySqlCommand cnt = new MySqlCommand("SELECT COUNT(*) FROM Test", conn);
- Int64 count = (Int64)cnt.ExecuteScalar();
-
- MySqlCommand cmd = new MySqlCommand("DELETE FROM Test WHERE name=?name", conn);
- cmd.Parameters.Add("?name", MySqlDbType.VarChar);
- cmd.Parameters[0].Value = "\u2032 OR 1=1;-- --";
- cmd.ExecuteNonQuery();
-
- Assert.AreEqual(count, (Int64)cnt.ExecuteScalar());
- }
-
- /// <summary>
- /// Bug #44194 ExecuteNonQuery for update commands does not match actual rows updated
- /// </summary>
- [Test]
- public void UseAffectedRows()
- {
- execSQL("CREATE TABLE Test (id INT, name VARCHAR(20))");
- execSQL("INSERT INTO Test VALUES (1, 'A')");
- execSQL("INSERT INTO Test VALUES (2, 'B')");
- execSQL("INSERT INTO Test VALUES (3, 'C')");
-
- MySqlCommand cmd = new MySqlCommand("UPDATE Test SET name='C' WHERE id=3", conn);
- Assert.AreEqual(1, cmd.ExecuteNonQuery());
-
- string conn_str = GetConnectionString(true) + ";use affected rows=true";
- using (MySqlConnection c = new MySqlConnection(conn_str))
- {
- c.Open();
- cmd.Connection = c;
- Assert.AreEqual(0, cmd.ExecuteNonQuery());
- }
- }
-
- /// <summary>
- /// Bug #45502 error if "Allow Batch=False"
- /// </summary>
- [Test]
- public void DontAllowBatching()
- {
- string connStr = GetConnectionString(true) + ";allow batch=false;character set=utf8";
- using (MySqlConnection c = new MySqlConnection(connStr))
- {
- c.Open();
- MySqlCommand cmd = new MySqlCommand("SELECT 1", c);
- cmd.ExecuteScalar();
- }
- }
-
- [Test]
- public void TableCommandType()
- {
- execSQL("CREATE TABLE Test (id INT, name VARCHAR(20))");
- execSQL("INSERT INTO Test VALUES (1, 'A')");
- execSQL("CREATE TABLE Test1 (id INT, name VARCHAR(20))");
- execSQL("INSERT INTO Test1 VALUES (2, 'B')");
-
- MySqlCommand cmd = new MySqlCommand("Test,Test1", conn);
- cmd.CommandType = CommandType.TableDirect;
- using (MySqlDataReader reader = cmd.ExecuteReader())
- {
- reader.Read();
- Assert.AreEqual(1, reader.GetInt32(0));
- Assert.AreEqual("A", reader.GetString(1));
- Assert.AreEqual(2, reader.GetInt32(2));
- Assert.AreEqual("B", reader.GetString(3));
- }
- }
-
- /// <summary>
- /// Bug #57501 MySql Connector/NET 6.3.5.0 fails to read from DataReader
- /// </summary>
- [Test]
- public void HelperTest()
- {
- string connStr = GetConnectionString(true);
- using (MySqlDataReader reader = MySqlHelper.ExecuteReader(connStr, "SHOW TABLES"))
- {
- while (reader.Read())
- {
- }
- }
- }
-
- /// <summary>
- /// Bug #58652 ExecuteReader throws NullReferenceException when using CommandBehavior.Close
- /// </summary>
- [Test]
- public void SyntaxErrorWithCloseConnection()
- {
- string connStr = GetConnectionString(true);
- using (MySqlConnection c = new MySqlConnection(connStr))
- {
- c.Open();
- MySqlCommand cmd = new MySqlCommand("SELE 1", c);
- try
- {
- cmd.ExecuteReader(CommandBehavior.CloseConnection);
- Assert.Fail("This should have failed");
- }
- catch (MySqlException)
- {
- }
- Assert.IsTrue(c.State == ConnectionState.Closed);
- }
- }
-
- /// <summary>
- /// Bug #59537 Different behavior from console and
- /// </summary>
- [Test]
- public void EmptyOrJustSemiCommand()
- {
- MySqlCommand cmd = new MySqlCommand("", conn);
- try
- {
- cmd.ExecuteNonQuery();
- Assert.Fail("Should not get here");
- }
- catch (InvalidOperationException)
- {
- }
-
- cmd.CommandText = ";";
- try
- {
- cmd.ExecuteNonQuery();
- }
- catch (MySqlException)
- {
- }
- }
-
-#if !CF
- /// <summary>
- /// Bug #59616 Only INSERTs are batched
- /// </summary>
- [Test]
- public void BatchUpdatesAndDeletes()
- {
- execSQL("CREATE TABLE test (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(20))");
- execSQL("INSERT INTO test VALUES (1, 'boo'), (2, 'boo'), (3, 'boo')");
-
- MySqlTrace.Listeners.Clear();
- MySqlTrace.Switch.Level = SourceLevels.All;
- GenericListener listener = new GenericListener();
- MySqlTrace.Listeners.Add(listener);
-
- string connStr = GetConnectionString(true) + ";logging=true;allow batch=true";
- using (MySqlConnection c = new MySqlConnection(connStr))
- {
- c.Open();
- MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM test", c);
- MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
- da.UpdateCommand = cb.GetUpdateCommand();
- da.UpdateCommand.UpdatedRowSource = UpdateRowSource.None;
- da.UpdateBatchSize = 100;
-
- DataTable dt = new DataTable();
- da.Fill(dt);
-
- dt.Rows[0]["name"] = "boo2";
- dt.Rows[1]["name"] = "boo2";
- dt.Rows[2]["name"] = "boo2";
- da.Update(dt);
- }
-
- Assert.AreEqual(1, listener.Find("Query Opened: UPDATE"));
- }
-#endif
-
- [Test]
- public void ExecuteReaderReturnsReaderAfterCancel()
- {
- execSQL("DROP TABLE IF EXISTS TableWithDateAsPrimaryKey");
- execSQL("DROP TABLE IF EXISTS TableWithStringAsPrimaryKey");
- createTable("CREATE TABLE TableWithDateAsPrimaryKey(PrimaryKey date NOT NULL, PRIMARY KEY (PrimaryKey))", "InnoDB");
- createTable("CREATE TABLE TableWithStringAsPrimaryKey(PrimaryKey nvarchar(50) NOT NULL, PRIMARY KEY (PrimaryKey))", "InnoDB");
-
- string connStr = GetConnectionString(true);
- using (MySqlConnection connection = new MySqlConnection(connStr))
- {
- connection.Open();
- MySqlCommand command = new MySqlCommand("SELECT PrimaryKey FROM TableWithDateAsPrimaryKey", connection);
- IDataReader reader = command.ExecuteReader(CommandBehavior.KeyInfo);
- DataTable dataTableSchema = reader.GetSchemaTable();
- command.Cancel();
- reader.Close();
-
- command = new MySqlCommand("SELECT PrimaryKey FROM TableWithStringAsPrimaryKey", connection);
- reader = command.ExecuteReader(CommandBehavior.KeyInfo);
- Assert.IsNotNull(reader);
-
- dataTableSchema = reader.GetSchemaTable();
- Assert.AreEqual("PrimaryKey", dataTableSchema.Rows[0][dataTableSchema.Columns[0]]);
-
- reader.Close();
- }
- }
- }
-
-
- #region Configs
-
- public class CommandTestsSocketCompressed : CommandTests
- {
- protected override string GetConnectionInfo()
- {
- return String.Format("port={0};compress=true", port);
- }
- }
-
-#if !CF
- [Category("Pipe")]
- public class CommandTestsPipe : CommandTests
- {
- protected override string GetConnectionInfo()
- {
- return String.Format("protocol=namedpipe;pipe name={0}", pipeName);
- }
- }
-
- [Category("Compressed")]
- [Category("Pipe")]
- public class CommandTestsPipeCompressed : CommandTests
- {
- protected override string GetConnectionInfo()
- {
- return String.Format("protocol=namedpipe;pipe name={0};compress=true", pipeName);
- }
- }
-
- [Category("SharedMemory")]
- public class CommandTestsSharedMemory : CommandTests
- {
- protected override string GetConnectionInfo()
- {
- return String.Format("protocol=sharedmemory; shared memory name={0}", memoryName);
- }
- }
-
- [Category("Compressed")]
- [Category("SharedMemory")]
- public class CommandTestsSharedMemoryCompressed : CommandTests
- {
- protected override string GetConnectionInfo()
- {
- return String.Format("protocol=sharedmemory; shared memory name={0};compress=true", memoryName);
- }
- }
-#endif
- #endregion
+ /// <summary>
+ /// Bug #7248 There is already an open DataReader associated with this Connection which must
+ /// </summary>
+ [Test]
+ public void GenWarnings()
+ {
+ execSQL("CREATE TABLE Test (id INT, dt DATETIME)");
+ execSQL("INSERT INTO Test VALUES (1, NOW())");
+ execSQL("INSERT INTO Test VALUES (2, NOW())");
+ execSQL("INSERT INTO Test VALUES (3, NOW())");
+
+ MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test WHERE dt = '" +
+ DateTime.Now + "'", conn);
+ DataSet ds = new DataSet();
+ da.Fill(ds);
+ }
+
+ /// <summary>
+ /// Bug #11991 ExecuteScalar
+ /// </summary>
+ [Test]
+ public void CloseReaderAfterFailedConvert()
+ {
+ execSQL("CREATE TABLE Test (dt DATETIME)");
+ execSQL("INSERT INTO Test VALUES ('00-00-0000 00:00:00')");
+
+ MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", conn);
+ try
+ {
+ cmd.ExecuteScalar();
+ }
+ catch (Exception)
+ {
+ }
+
+ conn.BeginTransaction();
+ }
+
+ /// <summary>
+ /// Bug #25443 ExecuteScalar() hangs when more than one bad result
+ /// </summary>
+ [Test]
+ public void ExecuteWithOneBadQuery()
+ {
+ MySqlCommand command = new MySqlCommand("SELECT 1; SELECT * FROM foo", conn);
+ try
+ {
+ command.ExecuteScalar();
+ }
+ catch (MySqlException)
+ {
+ }
+
+ // now try using ExecuteNonQuery
+ try
+ {
+ command.ExecuteNonQuery();
+ }
+ catch (MySqlException)
+ {
+ }
+ }
+
+ /// <summary>
+ /// Bug #27958 Cannot use Data Source Configuration Wizard on large databases
+ /// </summary>
+ [Test]
+ public void DefaultCommandTimeout()
+ {
+ MySqlConnection c = new MySqlConnection("server=localhost");
+ MySqlCommand cmd = new MySqlCommand("", c);
+ Assert.AreEqual(30, cmd.CommandTimeout);
+
+ c = new MySqlConnection("server=localhost;default command timeout=47");
+ cmd = new MySqlCommand("", c);
+ Assert.AreEqual(47, cmd.CommandTimeout);
+
+ cmd = new MySqlCommand("");
+ Assert.AreEqual(30, cmd.CommandTimeout);
+
+ cmd.CommandTimeout = 66;
+ cmd.Connection = c;
+ Assert.AreEqual(66, cmd.CommandTimeout);
+ cmd.CommandTimeout = 0;
+ Assert.AreEqual(0, cmd.CommandTimeout);
+
+ c = new MySqlConnection("server=localhost;default command timeout=0");
+ cmd = new MySqlCommand("", c);
+ Assert.AreEqual(0, cmd.CommandTimeout);
+ }
+
+ /// <summary>
+ /// Bug #38276 Short circuit evaluation error in MySqlCommand.CheckState()
+ /// </summary>
+ [Test]
+ public void SetNullConnection()
+ {
+ MySqlCommand command = new MySqlCommand();
+ command.CommandText = "SELECT 1";
+ command.Connection = null;
+ try
+ {
+ object o = command.ExecuteScalar();
+ }
+ catch (InvalidOperationException)
+ {
+ }
+ }
+
+ /// <summary>
+ /// Bug #45941 SQL-Injection attack
+ /// </summary>
+ [Test]
+ public void SqlInjection1()
+ {
+ execSQL("DROP TABLE IF EXISTS Test");
+ execSQL("CREATE TABLE Test(name VARCHAR(100)) ENGINE=MyISAM DEFAULT CHARSET=utf8");
+ execSQL("INSERT INTO Test VALUES ('name1'), ('name2'), ('name3')");
+
+ MySqlCommand cnt = new MySqlCommand("SELECT COUNT(*) FROM Test", conn);
+ Int64 count = (Int64)cnt.ExecuteScalar();
+
+ MySqlCommand cmd = new MySqlCommand("DELETE FROM Test WHERE name=?name", conn);
+ cmd.Parameters.Add("?name", MySqlDbType.VarChar);
+ cmd.Parameters[0].Value = "\u2032 OR 1=1;-- --";
+ cmd.ExecuteNonQuery();
+
+ Assert.AreEqual(count, (Int64)cnt.ExecuteScalar());
+ }
+
+ /// <summary>
+ /// Bug #44194 ExecuteNonQuery for update commands does not match actual rows updated
+ /// </summary>
+ [Test]
+ public void UseAffectedRows()
+ {
+ execSQL("CREATE TABLE Test (id INT, name VARCHAR(20))");
+ execSQL("INSERT INTO Test VALUES (1, 'A')");
+ execSQL("INSERT INTO Test VALUES (2, 'B')");
+ execSQL("INSERT INTO Test VALUES (3, 'C')");
+
+ MySqlCommand cmd = new MySqlCommand("UPDATE Test SET name='C' WHERE id=3", conn);
+ Assert.AreEqual(1, cmd.ExecuteNonQuery());
+
+ string conn_str = GetConnectionString(true) + ";use affected rows=true";
+ using (MySqlConnection c = new MySqlConnection(conn_str))
+ {
+ c.Open();
+ cmd.Connection = c;
+ Assert.AreEqual(0, cmd.ExecuteNonQuery());
+ }
+ }
+
+ /// <summary>
+ /// Bug #45502 error if "Allow Batch=False"
+ /// </summary>
+ [Test]
+ public void DontAllowBatching()
+ {
+ string connStr = GetConnectionString(true) + ";allow batch=false;character set=utf8";
+ using (MySqlConnection c = new MySqlConnection(connStr))
+ {
+ c.Open();
+ MySqlCommand cmd = new MySqlCommand("SELECT 1", c);
+ cmd.ExecuteScalar();
+ }
+ }
+
+ [Test]
+ public void TableCommandType()
+ {
+ execSQL("CREATE TABLE Test (id INT, name VARCHAR(20))");
+ execSQL("INSERT INTO Test VALUES (1, 'A')");
+ execSQL("CREATE TABLE Test1 (id INT, name VARCHAR(20))");
+ execSQL("INSERT INTO Test1 VALUES (2, 'B')");
+
+ MySqlCommand cmd = new MySqlCommand("Test,Test1", conn);
+ cmd.CommandType = CommandType.TableDirect;
+ using (MySqlDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ Assert.AreEqual(1, reader.GetInt32(0));
+ Assert.AreEqual("A", reader.GetString(1));
+ Assert.AreEqual(2, reader.GetInt32(2));
+ Assert.AreEqual("B", reader.GetString(3));
+ }
+ }
+
+ /// <summary>
+ /// Bug #57501 MySql Connector/NET 6.3.5.0 fails to read from DataReader
+ /// </summary>
+ [Test]
+ public void HelperTest()
+ {
+ string connStr = GetConnectionString(true);
+ using (MySqlDataReader reader = MySqlHelper.ExecuteReader(connStr, "SHOW TABLES"))
+ {
+ while (reader.Read())
+ {
+ }
+ }
+ }
+
+ /// <summary>
+ /// Bug #58652 ExecuteReader throws NullReferenceException when using CommandBehavior.Close
+ /// </summary>
+ [Test]
+ public void SyntaxErrorWithCloseConnection()
+ {
+ string connStr = GetConnectionString(true);
+ using (MySqlConnection c = new MySqlConnection(connStr))
+ {
+ c.Open();
+ MySqlCommand cmd = new MySqlCommand("SELE 1", c);
+ try
+ {
+ cmd.ExecuteReader(CommandBehavior.CloseConnection);
+ Assert.Fail("This should have failed");
+ }
+ catch (MySqlException)
+ {
+ }
+ Assert.IsTrue(c.State == ConnectionState.Closed);
+ }
+ }
+
+ /// <summary>
+ /// Bug #59537 Different behavior from console and
+ /// </summary>
+ [Test]
+ public void EmptyOrJustSemiCommand()
+ {
+ MySqlCommand cmd = new MySqlCommand("", conn);
+ try
+ {
+ cmd.ExecuteNonQuery();
+ Assert.Fail("Should not get here");
+ }
+ catch (InvalidOperationException)
+ {
+ }
+
+ cmd.CommandText = ";";
+ try
+ {
+ cmd.ExecuteNonQuery();
+ }
+ catch (MySqlException)
+ {
+ }
+ }
+
+#if !CF
+ /// <summary>
+ /// Bug #59616 Only INSERTs are batched
+ /// </summary>
+ [Test]
+ public void BatchUpdatesAndDeletes()
+ {
+ execSQL("CREATE TABLE test (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(20))");
+ execSQL("INSERT INTO test VALUES (1, 'boo'), (2, 'boo'), (3, 'boo')");
+
+ MySqlTrace.Listeners.Clear();
+ MySqlTrace.Switch.Level = SourceLevels.All;
+ GenericListener listener = new GenericListener();
+ MySqlTrace.Listeners.Add(listener);
+
+ string connStr = GetConnectionString(true) + ";logging=true;allow batch=true";
+ using (MySqlConnection c = new MySqlConnection(connStr))
+ {
+ c.Open();
+ MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM test", c);
+ MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
+ da.UpdateCommand = cb.GetUpdateCommand();
+ da.UpdateCommand.UpdatedRowSource = UpdateRowSource.None;
+ da.UpdateBatchSize = 100;
+
+ DataTable dt = new DataTable();
+ da.Fill(dt);
+
+ dt.Rows[0]["name"] = "boo2";
+ dt.Rows[1]["name"] = "boo2";
+ dt.Rows[2]["name"] = "boo2";
+ da.Update(dt);
+ }
+
+ Assert.AreEqual(1, listener.Find("Query Opened: UPDATE"));
+ }
+#endif
+
+ [Test]
+ public void ExecuteReaderReturnsReaderAfterCancel()
+ {
+ execSQL("DROP TABLE IF EXISTS TableWithDateAsPrimaryKey");
+ execSQL("DROP TABLE IF EXISTS TableWithStringAsPrimaryKey");
+ createTable("CREATE TABLE TableWithDateAsPrimaryKey(PrimaryKey date NOT NULL, PRIMARY KEY (PrimaryKey))", "InnoDB");
+ createTable("CREATE TABLE TableWithStringAsPrimaryKey(PrimaryKey nvarchar(50) NOT NULL, PRIMARY KEY (PrimaryKey))", "InnoDB");
+
+ string connStr = GetConnectionString(true);
+ using (MySqlConnection connection = new MySqlConnection(connStr))
+ {
+ connection.Open();
+ MySqlCommand command = new MySqlCommand("SELECT PrimaryKey FROM TableWithDateAsPrimaryKey", connection);
+ IDataReader reader = command.ExecuteReader(CommandBehavior.KeyInfo);
+ DataTable dataTableSchema = reader.GetSchemaTable();
+ command.Cancel();
+ reader.Close();
+
+ command = new MySqlCommand("SELECT PrimaryKey FROM TableWithStringAsPrimaryKey", connection);
+ reader = command.ExecuteReader(CommandBehavior.KeyInfo);
+ Assert.IsNotNull(reader);
+
+ dataTableSchema = reader.GetSchemaTable();
+ Assert.AreEqual("PrimaryKey", dataTableSchema.Rows[0][dataTableSchema.Columns[0]]);
+
+ reader.Close();
+ }
+ }
+ }
+
+
+ #region Configs
+
+ public class CommandTestsSocketCompressed : CommandTests
+ {
+ protected override string GetConnectionInfo()
+ {
+ return String.Format("port={0};compress=true", port);
+ }
+ }
+
+#if !CF
+ [Category("Pipe")]
+ public class CommandTestsPipe : CommandTests
+ {
+ protected override string GetConnectionInfo()
+ {
+ return String.Format("protocol=namedpipe;pipe name={0}", pipeName);
+ }
+ }
+
+ [Category("Compressed")]
+ [Category("Pipe")]
+ public class CommandTestsPipeCompressed : CommandTests
+ {
+ protected override string GetConnectionInfo()
+ {
+ return String.Format("protocol=namedpipe;pipe name={0};compress=true", pipeName);
+ }
+ }
+
+ [Category("SharedMemory")]
+ public class CommandTestsSharedMemory : CommandTests
+ {
+ protected override string GetConnectionInfo()
+ {
+ return String.Format("protocol=sharedmemory; shared memory name={0}", memoryName);
+ }
+ }
+
+ [Category("Compressed")]
+ [Category("SharedMemory")]
+ public class CommandTestsSharedMemoryCompressed : CommandTests
+ {
+ protected override string GetConnectionInfo()
+ {
+ return String.Format("protocol=sharedmemory; shared memory name={0};compress=true", memoryName);
+ }
+ }
+#endif
+ #endregion
}
=== modified file 'Tests/MySql.Data.Tests/ConnectionTests.cs'
--- a/Tests/MySql.Data.Tests/ConnectionTests.cs 2011-06-21 18:51:27 +0000
+++ b/Tests/MySql.Data.Tests/ConnectionTests.cs 2011-06-23 15:01:13 +0000
@@ -382,6 +382,7 @@
closed = true;
}
}
+
[Test]
public void ConnectionCloseByGC()
{
@@ -400,6 +401,7 @@
MySqlCommand cmd = new MySqlCommand("KILL " + threadId, conn);
cmd.ExecuteNonQuery();
}
+
/// <summary>
/// Bug #30964 StateChange imperfection
/// </summary>
Attachment: [text/bzr-bundle] bzr/reggie.burnett@oracle.com-20110623150113-v5k1c20j3onpecls.bundle
| Thread |
|---|
| • bzr commit into connector-net-6.3 branch (reggie.burnett:1019) | Reggie Burnett | 23 Jun |