Modified:
branches/1.0/TestSuite/BlobTests.cs
branches/1.0/TestSuite/CommandTests.cs
branches/1.0/mysqlclient/CharSetMap.cs
branches/1.0/mysqlclient/Field.cs
branches/1.0/mysqlclient/datareader.cs
branches/1.0/mysqlclient/nativedriver.cs
Log:
1. some whitespace cleanups
2. added max length value to character set mapping so we can calculate the "character" length of varchar fields
Modified: branches/1.0/TestSuite/BlobTests.cs
===================================================================
--- branches/1.0/TestSuite/BlobTests.cs 2006-10-17 22:41:15 UTC (rev 411)
+++ branches/1.0/TestSuite/BlobTests.cs 2006-10-18 14:49:09 UTC (rev 412)
@@ -39,22 +39,22 @@
}
[TestFixtureTearDown]
- public void TestFixtureTearDown()
+ public void TestFixtureTearDown()
{
Close();
}
- protected override void Setup()
- {
- base.Setup();
+ protected override void Setup()
+ {
+ base.Setup();
- execSQL("DROP TABLE IF EXISTS Test");
- execSQL("CREATE TABLE Test (id INT NOT NULL, blob1 LONGBLOB, text1 LONGTEXT, PRIMARY KEY(id))");
- }
+ execSQL("DROP TABLE IF EXISTS Test");
+ execSQL("CREATE TABLE Test (id INT NOT NULL, blob1 LONGBLOB, text1 LONGTEXT, PRIMARY KEY(id))");
+ }
[Test]
[Category("4.0")]
- public void InsertBinary()
+ public void InsertBinary()
{
int lenIn = 400000;
byte[] dataIn = Utils.CreateBlob(lenIn);
@@ -69,8 +69,8 @@
cmd.ExecuteNonQuery();
cmd.CommandText = "INSERT INTO Test VALUES (?id, ?b1, NULL)";
- cmd.Parameters.Add( new MySqlParameter("?id", 1));
- cmd.Parameters.Add( new MySqlParameter("?b1", dataIn));
+ cmd.Parameters.Add(new MySqlParameter("?id", 1));
+ cmd.Parameters.Add(new MySqlParameter("?b1", dataIn));
int rows = cmd.ExecuteNonQuery();
byte[] dataIn2 = Utils.CreateBlob(lenIn);
@@ -78,53 +78,53 @@
cmd.Parameters[1].Value = dataIn2;
rows += cmd.ExecuteNonQuery();
- Assert.AreEqual( 2, rows, "Checking insert rowcount" );
+ Assert.AreEqual(2, rows, "Checking insert rowcount");
MySqlDataReader reader = null;
- try
+ try
{
cmd.CommandText = "SELECT * FROM Test";
reader = cmd.ExecuteReader();
- Assert.AreEqual( true, reader.HasRows, "Checking HasRows" );
-
+ Assert.AreEqual(true, reader.HasRows, "Checking HasRows");
+
reader.Read();
- byte[] dataOut = new byte[ lenIn ];
- long lenOut = reader.GetBytes( 1, 0, dataOut, 0, lenIn );
+ 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)" );
+ 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 );
+ 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)
+ while (lenToRead > 0)
{
- int size = Math.Min( lenToRead, 1024 );
- int read = (int)reader.GetBytes( 1, pos, dataOut, pos, size );
+ 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 );
+ 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)" );
+ 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 );
+ for (int x = 0; x < dataIn2.Length; x++)
+ Assert.AreEqual(dataIn2[x], dataOut[x], "Checking second binary array at " + x);
}
- catch (Exception ex)
+ catch (Exception ex)
{
- Assert.Fail( ex.Message );
+ Assert.Fail(ex.Message);
}
- finally
+ finally
{
if (reader != null) reader.Close();
}
@@ -132,25 +132,25 @@
[Test]
[Category("4.0")]
- public void GetChars()
+ public void GetChars()
{
InternalGetChars(false);
}
- [Test]
- [Category("4.1")]
- public void GetCharsPrepared()
- {
- InternalGetChars(true);
- }
+ [Test]
+ [Category("4.1")]
+ public void GetCharsPrepared()
+ {
+ InternalGetChars(true);
+ }
- private void InternalGetChars(bool prepare)
+ private void InternalGetChars(bool prepare)
{
execSQL("TRUNCATE TABLE Test");
char[] data = new char[20000];
- for (int x=0; x < data.Length; x++)
- data[x] = (char)(65 + (x%20));
+ for (int x = 0; x < data.Length; x++)
+ data[x] = (char)(65 + (x % 20));
MySqlCommand cmd = new MySqlCommand("INSERT INTO Test VALUES (1, NULL, ?text1)", conn);
cmd.Parameters.Add("?text1", data);
@@ -159,11 +159,11 @@
cmd.ExecuteNonQuery();
cmd.CommandText = "SELECT * FROM Test";
- cmd.Parameters.Clear();
+ cmd.Parameters.Clear();
if (prepare)
cmd.Prepare();
MySqlDataReader reader = null;
- try
+ try
{
reader = cmd.ExecuteReader();
reader.Read();
@@ -172,7 +172,7 @@
char[] dataOut = new char[data.Length];
int pos = 0;
int lenToRead = data.Length;
- while (lenToRead > 0)
+ while (lenToRead > 0)
{
int size = Math.Min(lenToRead, 1024);
int read = (int)reader.GetChars(2, pos, dataOut, pos, size);
@@ -180,95 +180,95 @@
pos += read;
}
// now see if the buffer is intact
- for (int x=0; x < data.Length; x++)
+ for (int x = 0; x < data.Length; x++)
Assert.AreEqual(data[x], dataOut[x], "Checking first text array at " + x);
}
- catch (Exception ex)
+ catch (Exception ex)
{
Assert.Fail(ex.Message);
}
- finally
+ finally
{
- if (reader != null)
- reader.Close();
+ if (reader != null)
+ reader.Close();
}
}
[Test]
- public void InsertText()
+ public void InsertText()
{
InternalInsertText(false);
}
- [Test]
- [Category("4.1")]
- public void InsertTextPrepared()
- {
- InternalInsertText(true);
- }
+ [Test]
+ [Category("4.1")]
+ public void InsertTextPrepared()
+ {
+ InternalInsertText(true);
+ }
- private void InternalInsertText(bool prepare)
+ private void InternalInsertText(bool prepare)
{
byte[] data = new byte[1024];
- for (int x=0; x < 1024; x++)
- data[x] = (byte)(65 + (x%20));
+ for (int x = 0; x < 1024; x++)
+ data[x] = (byte)(65 + (x % 20));
// Create sample table
execSQL("TRUNCATE TABLE Test");
MySqlCommand cmd = new MySqlCommand("INSERT INTO Test VALUES (1, ?b1, ?t1)", conn);
- cmd.Parameters.Add( new MySqlParameter("?t1", data));
- cmd.Parameters.Add( new MySqlParameter("?b1", "This is my blob data"));
+ cmd.Parameters.Add(new MySqlParameter("?t1", data));
+ cmd.Parameters.Add(new MySqlParameter("?b1", "This is my blob data"));
if (prepare) cmd.Prepare();
int rows = cmd.ExecuteNonQuery();
- Assert.AreEqual( 1, rows, "Checking insert rowcount" );
+ Assert.AreEqual(1, rows, "Checking insert rowcount");
cmd.CommandText = "INSERT INTO Test VALUES(2, ?b1, ?t1)";
cmd.Parameters.Clear();
- cmd.Parameters.Add( "?t1", DBNull.Value );
+ cmd.Parameters.Add("?t1", DBNull.Value);
string str = "This is my text value";
- cmd.Parameters.Add( new MySqlParameter( "?b1", MySqlDbType.LongBlob, str.Length,
- ParameterDirection.Input, true, 0, 0, "b1", DataRowVersion.Current, str ) );
+ cmd.Parameters.Add(new MySqlParameter("?b1", MySqlDbType.LongBlob, str.Length,
+ ParameterDirection.Input, true, 0, 0, "b1", DataRowVersion.Current, str));
rows = cmd.ExecuteNonQuery();
- Assert.AreEqual( 1, rows, "Checking insert rowcount" );
+ Assert.AreEqual(1, rows, "Checking insert rowcount");
MySqlDataReader reader = null;
- try
+ try
{
cmd.CommandText = "SELECT * FROM Test";
if (prepare) cmd.Prepare();
reader = cmd.ExecuteReader();
- Assert.AreEqual( true, reader.HasRows, "Checking HasRows" );
-
- Assert.IsTrue( reader.Read() );
+ Assert.AreEqual(true, reader.HasRows, "Checking HasRows");
- Assert.AreEqual( "This is my blob data", reader.GetString(1));
+ Assert.IsTrue(reader.Read());
+
+ Assert.AreEqual("This is my blob data", reader.GetString(1));
string s = reader.GetString(2);
- Assert.AreEqual( 1024, s.Length, "Checking length returned " );
- Assert.AreEqual( "ABCDEFGHI", s.Substring(0, 9), "Checking first few chars of string" );
+ Assert.AreEqual(1024, s.Length, "Checking length returned ");
+ Assert.AreEqual("ABCDEFGHI", s.Substring(0, 9), "Checking first few chars of string");
- Assert.IsTrue( reader.Read() );
- Assert.AreEqual( DBNull.Value, reader.GetValue(2) );
- Assert.AreEqual( "This is my text value", reader.GetString(1) );
+ Assert.IsTrue(reader.Read());
+ Assert.AreEqual(DBNull.Value, reader.GetValue(2));
+ Assert.AreEqual("This is my text value", reader.GetString(1));
}
- catch (Exception ex)
+ catch (Exception ex)
{
- Assert.Fail( ex.Message );
+ Assert.Fail(ex.Message);
}
- finally
+ finally
{
if (reader != null) reader.Close();
}
}
[Test]
- public void UpdateDataSet()
+ public void UpdateDataSet()
{
- execSQL("DROP TABLE IF EXISTS Test");
- execSQL("CREATE TABLE Test (id INT NOT NULL, blob1 LONGBLOB, text1 LONGTEXT, PRIMARY KEY(id))");
- execSQL("INSERT INTO Test VALUES( 1, NULL, 'Text field' )");
+ execSQL("DROP TABLE IF EXISTS Test");
+ execSQL("CREATE TABLE Test (id INT NOT NULL, blob1 LONGBLOB, text1 LONGTEXT, PRIMARY KEY(id))");
+ execSQL("INSERT INTO Test VALUES( 1, NULL, 'Text field' )");
- try
+ try
{
MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
@@ -279,20 +279,20 @@
Assert.AreEqual("Text field", s);
byte[] inBuf = Utils.CreateBlob(512);
- dt.Rows[0].BeginEdit();
+ dt.Rows[0].BeginEdit();
dt.Rows[0]["blob1"] = inBuf;
- dt.Rows[0].EndEdit();
+ dt.Rows[0].EndEdit();
DataTable changes = dt.GetChanges();
- da.Update(changes);
+ da.Update(changes);
dt.AcceptChanges();
dt.Clear();
da.Fill(dt);
byte[] outBuf = (byte[])dt.Rows[0]["blob1"];
- Assert.AreEqual(inBuf.Length, outBuf.Length,
- "checking length of updated buffer");
- for (int y=0; y < inBuf.Length; y++)
+ Assert.AreEqual(inBuf.Length, outBuf.Length,
+ "checking length of updated buffer");
+ for (int y = 0; y < inBuf.Length; y++)
Assert.AreEqual(inBuf[y], outBuf[y], "checking array data");
}
catch (Exception ex)
@@ -303,156 +303,156 @@
[Test]
[Category("4.0")]
- public void GetCharsOnLongTextColumn()
+ public void GetCharsOnLongTextColumn()
{
execSQL("INSERT INTO Test (id, text1) VALUES(1, 'Test')");
MySqlCommand cmd = new MySqlCommand("SELECT id, text1 FROM Test", conn);
MySqlDataReader reader = null;
- try
+ try
{
char[] buf = new char[2];
reader = cmd.ExecuteReader();
reader.Read();
- reader.GetChars( 1, 0, buf, 0, 2 );
- Assert.AreEqual( 'T', buf[0] );
- Assert.AreEqual( 'e', buf[1] );
+ reader.GetChars(1, 0, buf, 0, 2);
+ Assert.AreEqual('T', buf[0]);
+ Assert.AreEqual('e', buf[1]);
}
- catch (Exception ex)
+ catch (Exception ex)
{
- Assert.Fail( ex.Message );
+ Assert.Fail(ex.Message);
}
- finally
+ finally
{
if (reader != null) reader.Close();
}
}
- [Test]
- public void MediumIntBlobSize()
- {
- execSQL("DROP TABLE IF EXISTS test");
- execSQL("CREATE TABLE test (id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, " +
- "image MEDIUMBLOB NOT NULL, imageSize MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT 0, " +
- "PRIMARY KEY (id))");
+ [Test]
+ public void MediumIntBlobSize()
+ {
+ execSQL("DROP TABLE IF EXISTS test");
+ execSQL("CREATE TABLE test (id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, " +
+ "image MEDIUMBLOB NOT NULL, imageSize MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT 0, " +
+ "PRIMARY KEY (id))");
- byte[] image = new byte[2048];
- for (int x = 0; x < image.Length; x++)
- image[x] = (byte)(x % 47);
- MySqlCommand cmd = new MySqlCommand("INSERT INTO test VALUES(NULL, ?image, ?size)", conn);
- cmd.Parameters.Add("?image", image);
- cmd.Parameters.Add("?size", image.Length);
- cmd.ExecuteNonQuery();
+ byte[] image = new byte[2048];
+ for (int x = 0; x < image.Length; x++)
+ image[x] = (byte)(x % 47);
+ MySqlCommand cmd = new MySqlCommand("INSERT INTO test VALUES(NULL, ?image, ?size)", conn);
+ cmd.Parameters.Add("?image", image);
+ cmd.Parameters.Add("?size", image.Length);
+ cmd.ExecuteNonQuery();
- cmd.CommandText = "SELECT imageSize, length(image), image FROM test WHERE id=?id";
- cmd.Parameters.Add("?id", 1);
- cmd.Prepare();
+ cmd.CommandText = "SELECT imageSize, length(image), image FROM test WHERE id=?id";
+ cmd.Parameters.Add("?id", 1);
+ cmd.Prepare();
- MySqlDataReader reader = null;
- try
- {
- reader = cmd.ExecuteReader();
- reader.Read();
- uint actualsize = reader.GetUInt32(1);
- Assert.AreEqual(image.Length, actualsize);
- uint size = reader.GetUInt32(0);
- byte[] outImage = new byte[size];
- long len = reader.GetBytes(reader.GetOrdinal("image"), 0, outImage, 0, (int)size);
- Assert.AreEqual(image.Length, size);
- Assert.AreEqual(image.Length, len);
- }
- catch (Exception ex)
- {
- Assert.Fail(ex.Message);
- }
- finally
- {
- if (reader != null)
- reader.Close();
- }
- }
+ MySqlDataReader reader = null;
+ try
+ {
+ reader = cmd.ExecuteReader();
+ reader.Read();
+ uint actualsize = reader.GetUInt32(1);
+ Assert.AreEqual(image.Length, actualsize);
+ uint size = reader.GetUInt32(0);
+ byte[] outImage = new byte[size];
+ long len = reader.GetBytes(reader.GetOrdinal("image"), 0, outImage, 0, (int)size);
+ Assert.AreEqual(image.Length, size);
+ Assert.AreEqual(image.Length, len);
+ }
+ catch (Exception ex)
+ {
+ Assert.Fail(ex.Message);
+ }
+ finally
+ {
+ if (reader != null)
+ reader.Close();
+ }
+ }
- [Test]
- public void BlobBiggerThanMaxPacket()
- {
- execSQL("set @@global.max_allowed_packet=500000");
+ [Test]
+ public void BlobBiggerThanMaxPacket()
+ {
+ execSQL("set @@global.max_allowed_packet=500000");
- execSQL("DROP TABLE IF EXISTS test");
- execSQL("CREATE TABLE test (id INT(10), image BLOB)");
+ execSQL("DROP TABLE IF EXISTS test");
+ execSQL("CREATE TABLE test (id INT(10), image BLOB)");
- MySqlConnection c = new MySqlConnection(GetConnectionString(true));
- try
- {
- c.Open();
- byte[] image = Utils.CreateBlob(1000000);
- MySqlCommand cmd = new MySqlCommand("INSERT INTO test VALUES(NULL, ?image)", c);
- cmd.Parameters.Add("?image", image);
- cmd.ExecuteNonQuery();
- Assert.Fail("This should have thrown an exception");
- }
- catch (Exception)
- {
- Assert.AreEqual(ConnectionState.Open, c.State);
- }
- finally
- {
- if (c != null)
- c.Close();
- execSQL("set @@global.max_allowed_packet=2000000");
- }
- }
- }
+ MySqlConnection c = new MySqlConnection(GetConnectionString(true));
+ try
+ {
+ c.Open();
+ byte[] image = Utils.CreateBlob(1000000);
+ MySqlCommand cmd = new MySqlCommand("INSERT INTO test VALUES(NULL, ?image)", c);
+ cmd.Parameters.Add("?image", image);
+ cmd.ExecuteNonQuery();
+ Assert.Fail("This should have thrown an exception");
+ }
+ catch (Exception)
+ {
+ Assert.AreEqual(ConnectionState.Open, c.State);
+ }
+ finally
+ {
+ if (c != null)
+ c.Close();
+ execSQL("set @@global.max_allowed_packet=2000000");
+ }
+ }
+ }
- #region Configs
+ #region Configs
- [Category("Compressed")]
- public class BlobTestsSocketCompressed : BlobTests
- {
- protected override string GetConnectionInfo()
- {
- return ";port=3306;compress=true";
- }
- }
+ [Category("Compressed")]
+ public class BlobTestsSocketCompressed : BlobTests
+ {
+ protected override string GetConnectionInfo()
+ {
+ return ";port=3306;compress=true";
+ }
+ }
- [Category("Pipe")]
- public class BlobTestsPipe : BlobTests
- {
- protected override string GetConnectionInfo()
- {
- return ";protocol=pipe";
- }
- }
+ [Category("Pipe")]
+ public class BlobTestsPipe : BlobTests
+ {
+ protected override string GetConnectionInfo()
+ {
+ return ";protocol=pipe";
+ }
+ }
- [Category("Compressed")]
- [Category("Pipe")]
- public class BlobTestsPipeCompressed : BlobTests
- {
- protected override string GetConnectionInfo()
- {
- return ";protocol=pipe;compress=true";
- }
- }
+ [Category("Compressed")]
+ [Category("Pipe")]
+ public class BlobTestsPipeCompressed : BlobTests
+ {
+ protected override string GetConnectionInfo()
+ {
+ return ";protocol=pipe;compress=true";
+ }
+ }
- [Category("SharedMemory")]
- public class BlobTestsSharedMemory : BlobTests
- {
- protected override string GetConnectionInfo()
- {
- return ";protocol=memory";
- }
- }
+ [Category("SharedMemory")]
+ public class BlobTestsSharedMemory : BlobTests
+ {
+ protected override string GetConnectionInfo()
+ {
+ return ";protocol=memory";
+ }
+ }
- [Category("Compressed")]
- [Category("SharedMemory")]
- public class BlobTestsSharedMemoryCompressed : BlobTests
- {
- protected override string GetConnectionInfo()
- {
- return ";protocol=memory;compress=true";
- }
- }
+ [Category("Compressed")]
+ [Category("SharedMemory")]
+ public class BlobTestsSharedMemoryCompressed : BlobTests
+ {
+ protected override string GetConnectionInfo()
+ {
+ return ";protocol=memory;compress=true";
+ }
+ }
- #endregion
+ #endregion
}
\ No newline at end of file
Modified: branches/1.0/TestSuite/CommandTests.cs
===================================================================
--- branches/1.0/TestSuite/CommandTests.cs 2006-10-17 22:41:15 UTC (rev 411)
+++ branches/1.0/TestSuite/CommandTests.cs 2006-10-18 14:49:09 UTC (rev 412)
@@ -37,56 +37,56 @@
}
[TestFixtureTearDown]
- public void TestFixtureTearDown()
+ public void TestFixtureTearDown()
{
Close();
}
- protected override void Setup()
- {
- base.Setup();
- execSQL("DROP TABLE IF EXISTS Test");
- execSQL("CREATE TABLE Test (id int NOT NULL, name VARCHAR(100))");
- }
+ protected override void Setup()
+ {
+ base.Setup();
+ execSQL("DROP TABLE IF EXISTS Test");
+ execSQL("CREATE TABLE Test (id int NOT NULL, name VARCHAR(100))");
+ }
[Test]
public void InsertTest()
{
- try
+ try
{
// 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" );
+ Assert.AreEqual(1, cnt, "Insert Count");
// make sure we get the right value back out
cmd.CommandText = "SELECT name FROM Test WHERE id=10";
string name = (string)cmd.ExecuteScalar();
- Assert.AreEqual( "Test", name, "Insert result" );
+ Assert.AreEqual("Test", name, "Insert result");
// now do the insert with parameters
cmd.CommandText = "INSERT INTO Test (id,name) VALUES(?id, ?name)";
- cmd.Parameters.Add( new MySqlParameter("?id", 11));
- cmd.Parameters.Add( new MySqlParameter("?name", "Test2"));
+ cmd.Parameters.Add(new MySqlParameter("?id", 11));
+ cmd.Parameters.Add(new MySqlParameter("?name", "Test2"));
cnt = cmd.ExecuteNonQuery();
- Assert.AreEqual( 1, cnt, "Insert with Parameters Count" );
+ Assert.AreEqual(1, cnt, "Insert with Parameters Count");
// make sure we get the right value back out
cmd.Parameters.Clear();
cmd.CommandText = "SELECT name FROM Test WHERE id=11";
name = (string)cmd.ExecuteScalar();
- Assert.AreEqual( "Test2", name, "Insert with parameters result" );
+ Assert.AreEqual("Test2", name, "Insert with parameters result");
}
catch (MySqlException ex)
{
- Assert.Fail( ex.Message );
+ Assert.Fail(ex.Message);
}
}
[Test]
public void UpdateTest()
{
- try
+ try
{
execSQL("INSERT INTO Test (id,name) VALUES(10, 'Test')");
execSQL("INSERT INTO Test (id,name) VALUES(11, 'Test2')");
@@ -102,15 +102,15 @@
cmd.CommandText = "SELECT name FROM Test WHERE id=10";
string name = (string)cmd.ExecuteScalar();
Assert.AreEqual("Test3", name);
-
+
cmd.CommandText = "SELECT name FROM Test WHERE id=11";
name = (string)cmd.ExecuteScalar();
Assert.AreEqual("Test3", name);
// now do the update with parameters
cmd.CommandText = "UPDATE Test SET name=?name WHERE id=?id";
- cmd.Parameters.Add( new MySqlParameter("?id", 11));
- cmd.Parameters.Add( new MySqlParameter("?name", "Test5"));
+ cmd.Parameters.Add(new MySqlParameter("?id", 11));
+ cmd.Parameters.Add(new MySqlParameter("?name", "Test5"));
cnt = cmd.ExecuteNonQuery();
Assert.AreEqual(1, cnt, "Update with Parameters Count");
@@ -129,7 +129,7 @@
[Test]
public void DeleteTest()
{
- try
+ try
{
execSQL("INSERT INTO Test (id, name) VALUES(1, 'Test')");
execSQL("INSERT INTO Test (id, name) VALUES(2, 'Test2')");
@@ -138,7 +138,7 @@
MySqlCommand cmd = new MySqlCommand("DELETE FROM Test WHERE id=1 or id=2", conn);
int delcnt = cmd.ExecuteNonQuery();
Assert.AreEqual(2, delcnt);
-
+
// find out how many rows we have now
cmd.CommandText = "SELECT COUNT(*) FROM Test";
object after_cnt = cmd.ExecuteScalar();
@@ -151,7 +151,7 @@
}
[Test]
- public void CtorTest()
+ public void CtorTest()
{
MySqlTransaction txn = conn.BeginTransaction();
MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", conn);
@@ -163,7 +163,7 @@
}
[Test]
- public void CloneCommand()
+ public void CloneCommand()
{
IDbCommand cmd = new MySqlCommand();
IDbCommand cmd2 = ((ICloneable)cmd).Clone() as IDbCommand;
@@ -173,57 +173,57 @@
[Test]
public void TableWithOVer100Columns()
{
- string sql = "create table IF NOT EXISTS zvan (id int(8) primary key " +
+ string sql = "create table IF NOT EXISTS zvan (id int(8) primary key " +
"unique auto_increment, name varchar(250)) TYPE=INNODB; ";
-/* "create table IF NOT EXISTS ljudyna (id int(8) primary key " +
- "unique auto_increment, name varchar(250), data_narod date, " +
- "id_in_zvan int(8), kandidat varchar(250), tel_rob_vn varchar(250), " +
- "tel_rob_mis varchar(250), n_kabin varchar(250), n_nak_zvan varchar(250), " +
- "d_nak_zvan date, sex tinyint(1), n_nak_pos varchar(250), " +
- "d_nak_pos date, posad_data varchar(250), visl1 varchar(250), visl2 " +
- "varchar(250), visl3 varchar(250), cpidr_f int(8), cposad_f int(8), sumis " +
- "tinyint(1), zs_s date, zs_po date, ovs_z date, ovs_po date, naiavn_zviln " +
- "tinyint(1), ovs_z1 date, ovs_po1 date, ovs_z2 date, ovs_po2 date, ovs_z3 date, " +
- "ovs_po3 date, ovs_prakt varchar(250), data_atest date, data_sp date, v_akad_z " +
- "date, z_akad_zvln tinyint(1), v_akad_period varchar(250), nauk_stup " +
- "varchar(250), vch_zvan varchar(250), n_sprav varchar(250), n_posv varchar(250), " +
- "nacional varchar(250), osvita varchar(250), osvita_zakin_sho varchar(250), " +
- "osvita_zakin_koli date, osvita_special varchar(250), osvita_kvalifikac " +
- "varchar(250), de_navchaet varchar(250), data_vstupu date, termin_navch " +
- "varchar(250), adresa varchar(250), tel_dom varchar(250), marka_avto " +
- "varchar(250), n_avto varchar(250), color_avto varchar(250), vikor_avto " +
- "varchar(250), posv_avto varchar(250), marka_zbr varchar(250), nomer_calibr_zbr " +
- "varchar(250), vid_zbr varchar(250), nomer_data_razreshen varchar(250), pasport " +
- "varchar(250), oklad1 varchar(250), prem07_2003 varchar(250), nadb07_2003 " +
- "varchar(250), osob_nom varchar(250), nadbavka_stag_max varchar(250), " +
- "nadbavka_stag_08_2003 varchar(250), nadbavka_stag_10_2003 varchar(250), " +
- "nadbavka_stag_11_2003 varchar(250), nadbavka_stag_02_2004 varchar(250), " +
- "vidp_vikoristav varchar(250), vidp_plan varchar(250), vidp_vidgil varchar(250), " +
- "vidp_nevidgil_dniv varchar(250), nadb111 varchar(250), prem_3_1 varchar(250), " +
- "nadb_4_1 varchar(250), prem_3_2 varchar(250), nadb_3_2 varchar(250), nedolos " +
- "varchar(250), sposl int(8), cposl int(8), czaoh int(8), 07_2003_oklad " +
- "varchar(250), 05_2003_oklad varchar(250), deti_jeni varchar(250), nadb_volny " +
- "varchar(250), prem_volny varchar(250), dispanser tinyint(1), posl_spisok " +
- "tinyint(1), anketa_avtobiogr tinyint(1), photokartka tinyint(1), sp1 tinyint(1), " +
- "inshe varchar(250), oklad2 varchar(250), slugbova tinyint(1), atestuvan " +
- "varchar(250), 09_2004_oklad_vstan varchar(250), golosuvannia varchar(250), " +
- "stag_kalendar varchar(250), data_stag_kalendar varchar(250), medali " +
- "varchar(250), medali_mae varchar(250), visluga_cal_ovs_and_zs varchar(250), " +
- "FOREIGN KEY (id_in_zvan) REFERENCES zvan(id) ON DELETE CASCADE ON UPDATE " +
- "CASCADE) TYPE=INNODB DEFAULT CHARACTER SET cp1251 COLLATE cp1251_ukrainian_ci";
- */
- try
+ /* "create table IF NOT EXISTS ljudyna (id int(8) primary key " +
+ "unique auto_increment, name varchar(250), data_narod date, " +
+ "id_in_zvan int(8), kandidat varchar(250), tel_rob_vn varchar(250), " +
+ "tel_rob_mis varchar(250), n_kabin varchar(250), n_nak_zvan varchar(250), " +
+ "d_nak_zvan date, sex tinyint(1), n_nak_pos varchar(250), " +
+ "d_nak_pos date, posad_data varchar(250), visl1 varchar(250), visl2 " +
+ "varchar(250), visl3 varchar(250), cpidr_f int(8), cposad_f int(8), sumis " +
+ "tinyint(1), zs_s date, zs_po date, ovs_z date, ovs_po date, naiavn_zviln " +
+ "tinyint(1), ovs_z1 date, ovs_po1 date, ovs_z2 date, ovs_po2 date, ovs_z3 date, " +
+ "ovs_po3 date, ovs_prakt varchar(250), data_atest date, data_sp date, v_akad_z " +
+ "date, z_akad_zvln tinyint(1), v_akad_period varchar(250), nauk_stup " +
+ "varchar(250), vch_zvan varchar(250), n_sprav varchar(250), n_posv varchar(250), " +
+ "nacional varchar(250), osvita varchar(250), osvita_zakin_sho varchar(250), " +
+ "osvita_zakin_koli date, osvita_special varchar(250), osvita_kvalifikac " +
+ "varchar(250), de_navchaet varchar(250), data_vstupu date, termin_navch " +
+ "varchar(250), adresa varchar(250), tel_dom varchar(250), marka_avto " +
+ "varchar(250), n_avto varchar(250), color_avto varchar(250), vikor_avto " +
+ "varchar(250), posv_avto varchar(250), marka_zbr varchar(250), nomer_calibr_zbr " +
+ "varchar(250), vid_zbr varchar(250), nomer_data_razreshen varchar(250), pasport " +
+ "varchar(250), oklad1 varchar(250), prem07_2003 varchar(250), nadb07_2003 " +
+ "varchar(250), osob_nom varchar(250), nadbavka_stag_max varchar(250), " +
+ "nadbavka_stag_08_2003 varchar(250), nadbavka_stag_10_2003 varchar(250), " +
+ "nadbavka_stag_11_2003 varchar(250), nadbavka_stag_02_2004 varchar(250), " +
+ "vidp_vikoristav varchar(250), vidp_plan varchar(250), vidp_vidgil varchar(250), " +
+ "vidp_nevidgil_dniv varchar(250), nadb111 varchar(250), prem_3_1 varchar(250), " +
+ "nadb_4_1 varchar(250), prem_3_2 varchar(250), nadb_3_2 varchar(250), nedolos " +
+ "varchar(250), sposl int(8), cposl int(8), czaoh int(8), 07_2003_oklad " +
+ "varchar(250), 05_2003_oklad varchar(250), deti_jeni varchar(250), nadb_volny " +
+ "varchar(250), prem_volny varchar(250), dispanser tinyint(1), posl_spisok " +
+ "tinyint(1), anketa_avtobiogr tinyint(1), photokartka tinyint(1), sp1 tinyint(1), " +
+ "inshe varchar(250), oklad2 varchar(250), slugbova tinyint(1), atestuvan " +
+ "varchar(250), 09_2004_oklad_vstan varchar(250), golosuvannia varchar(250), " +
+ "stag_kalendar varchar(250), data_stag_kalendar varchar(250), medali " +
+ "varchar(250), medali_mae varchar(250), visluga_cal_ovs_and_zs varchar(250), " +
+ "FOREIGN KEY (id_in_zvan) REFERENCES zvan(id) ON DELETE CASCADE ON UPDATE " +
+ "CASCADE) TYPE=INNODB DEFAULT CHARACTER SET cp1251 COLLATE cp1251_ukrainian_ci";
+ */
+ try
{
execSQL("DROP TABLE IF EXISTS zvan");
execSQL("DROP TABLE IF EXISTS ljudyna");
MySqlCommand cmd = new MySqlCommand(sql, conn);
cmd.ExecuteNonQuery();
}
- catch (Exception ex)
+ catch (Exception ex)
{
Assert.Fail(ex.Message);
}
- finally
+ finally
{
execSQL("DROP TABLE IF EXISTS zvan");
execSQL("DROP TABLE IF EXISTS ljudyna");
@@ -247,7 +247,7 @@
cmd.CommandText = "SELECT * FROM test";
MySqlDataReader reader = null;
- try
+ try
{
reader = cmd.ExecuteReader();
Assert.IsTrue(reader.Read());
@@ -257,7 +257,7 @@
{
Assert.Fail(ex.Message);
}
- finally
+ finally
{
if (reader != null) reader.Close();
}
@@ -278,7 +278,7 @@
cmd.CommandText = "SELECT * FROM test";
reader = null;
- try
+ try
{
reader = cmd.ExecuteReader();
Assert.IsTrue(reader.Read());
@@ -289,152 +289,152 @@
{
Assert.Fail(ex.Message);
}
- finally
+ finally
{
if (reader != null) reader.Close();
}
}
- /// <summary>
- /// Bug# 8119. Unable to reproduce but left in anyway
- /// </summary>
- [Category("NotWorking")]
- [Test]
- public void ReallyBigCommandString()
- {
- System.Text.StringBuilder sql = new System.Text.StringBuilder();
+ /// <summary>
+ /// Bug# 8119. Unable to reproduce but left in anyway
+ /// </summary>
+ [Category("NotWorking")]
+ [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);");
+ 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);
- }
+ 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);
+ }
- try
- {
- MySqlCommand cmd = new MySqlCommand(sql.ToString(), conn);
- cmd.ExecuteNonQuery();
+ try
+ {
+ 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);
- }
- }
- catch (Exception ex)
- {
- Assert.Fail(ex.Message);
- }
+ 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);
+ }
+ }
+ catch (Exception ex)
+ {
+ Assert.Fail(ex.Message);
+ }
- }
+ }
- /// <summary>
- /// Bug #7248 There is already an open DataReader associated with this Connection which must
- /// </summary>
- [Test]
- public void GenWarnings()
- {
- execSQL("DROP TABLE IF EXISTS test");
- 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())");
+ /// <summary>
+ /// Bug #7248 There is already an open DataReader associated with this Connection which must
+ /// </summary>
+ [Test]
+ public void GenWarnings()
+ {
+ execSQL("DROP TABLE IF EXISTS test");
+ 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);
- }
+ 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("DROP TABLE IF EXISTS test");
- execSQL("CREATE TABLE test (dt DATETIME)");
- execSQL("INSERT INTO test VALUES ('00-00-0000 00:00:00')");
+ /// <summary>
+ /// Bug #11991 ExecuteScalar
+ /// </summary>
+ [Test]
+ public void CloseReaderAfterFailedConvert()
+ {
+ execSQL("DROP TABLE IF EXISTS test");
+ 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
- {
- object o = cmd.ExecuteScalar();
- }
- catch (Exception)
- {
- }
+ MySqlCommand cmd = new MySqlCommand("SELECT * FROM test", conn);
+ try
+ {
+ object o = cmd.ExecuteScalar();
+ }
+ catch (Exception)
+ {
+ }
- try
- {
- IDbTransaction trans = conn.BeginTransaction();
- trans.Rollback();
- }
- catch (Exception ex)
- {
- Assert.Fail(ex.Message);
- }
- }
+ try
+ {
+ IDbTransaction trans = conn.BeginTransaction();
+ trans.Rollback();
+ }
+ catch (Exception ex)
+ {
+ Assert.Fail(ex.Message);
+ }
+ }
}
- #region Configs
+ #region Configs
- [Category("Compressed")]
- public class CommandTestsSocketCompressed : CommandTests
- {
- protected override string GetConnectionInfo()
- {
- return ";port=3306;compress=true";
- }
- }
+ [Category("Compressed")]
+ public class CommandTestsSocketCompressed : CommandTests
+ {
+ protected override string GetConnectionInfo()
+ {
+ return ";port=3306;compress=true";
+ }
+ }
- [Category("Pipe")]
- public class CommandTestsPipe : CommandTests
- {
- protected override string GetConnectionInfo()
- {
- return ";protocol=pipe";
- }
- }
+ [Category("Pipe")]
+ public class CommandTestsPipe : CommandTests
+ {
+ protected override string GetConnectionInfo()
+ {
+ return ";protocol=pipe";
+ }
+ }
- [Category("Compressed")]
- [Category("Pipe")]
- public class CommandTestsPipeCompressed : CommandTests
- {
- protected override string GetConnectionInfo()
- {
- return ";protocol=pipe;compress=true";
- }
- }
+ [Category("Compressed")]
+ [Category("Pipe")]
+ public class CommandTestsPipeCompressed : CommandTests
+ {
+ protected override string GetConnectionInfo()
+ {
+ return ";protocol=pipe;compress=true";
+ }
+ }
- [Category("SharedMemory")]
- public class CommandTestsSharedMemory : CommandTests
- {
- protected override string GetConnectionInfo()
- {
- return ";protocol=memory";
- }
- }
+ [Category("SharedMemory")]
+ public class CommandTestsSharedMemory : CommandTests
+ {
+ protected override string GetConnectionInfo()
+ {
+ return ";protocol=memory";
+ }
+ }
- [Category("Compressed")]
- [Category("SharedMemory")]
- public class CommandTestsSharedMemoryCompressed : CommandTests
- {
- protected override string GetConnectionInfo()
- {
- return ";protocol=memory;compress=true";
- }
- }
+ [Category("Compressed")]
+ [Category("SharedMemory")]
+ public class CommandTestsSharedMemoryCompressed : CommandTests
+ {
+ protected override string GetConnectionInfo()
+ {
+ return ";protocol=memory;compress=true";
+ }
+ }
- #endregion
+ #endregion
}
Modified: branches/1.0/mysqlclient/CharSetMap.cs
===================================================================
--- branches/1.0/mysqlclient/CharSetMap.cs 2006-10-17 22:41:15 UTC (rev 411)
+++ branches/1.0/mysqlclient/CharSetMap.cs 2006-10-18 14:49:09 UTC (rev 412)
@@ -36,35 +36,40 @@
internal class CharSetMap
{
#if NET20
- private static Dictionary<string, string> mapping;
+ private static Dictionary<string, CharacterSet> mapping;
#else
- private static StringDictionary mapping;
+ private static Hashtable mapping;
#endif
- // we use a static constructor here since we only want to init
- // the mapping once
- static CharSetMap()
+ // we use a static constructor here since we only want to init
+ // the mapping once
+ static CharSetMap()
{
- InitializeMapping();
- }
+ InitializeMapping();
+ }
+ public static CharacterSet GetChararcterSet(DBVersion version, string CharSetName)
+ {
+ CharacterSet cs = mapping[CharSetName];
+ if (cs == null)
+ throw new MySqlException("Character set '" + CharSetName + "' is not supported");
+ return cs;
+ }
+
/// <summary>
/// Returns the text encoding for a given MySQL character set name
/// </summary>
/// <param name="version">Version of the connection requesting the encoding</param>
/// <param name="CharSetName">Name of the character set to get the encoding for</param>
/// <returns>Encoding object for the given character set name</returns>
- public static Encoding GetEncoding(DBVersion version, string CharSetName)
+ public static Encoding GetEncoding(DBVersion version, string CharSetName)
{
- try
+ try
{
- string encodingName = mapping[CharSetName];
- if (encodingName == null)
- throw new MySqlException("Character set '" + CharSetName + "' is not supported");
-
- return Encoding.GetEncoding(encodingName);
+ CharacterSet cs = GetChararcterSet(version, CharSetName);
+ return Encoding.GetEncoding(cs.name);
}
- catch (System.NotSupportedException)
+ catch (System.NotSupportedException)
{
return Encoding.GetEncoding(0);
}
@@ -81,62 +86,80 @@
private static void LoadCharsetMap()
{
#if NET20
- mapping = new Dictionary<string, string>();
+ mapping = new Dictionary<string, CharacterSet>();
#else
- mapping = new StringDictionary();
+ mapping = new Hashtable()
#endif
- mapping.Add("big5", "big5");
- mapping.Add("sjis", "sjis");
- mapping.Add("gb2312", "gb2312");
- mapping.Add("latin1", "latin1");
- mapping.Add("latin2", "latin2");
- mapping.Add("latin3", "latin3");
- mapping.Add("latin4", "latin4");
- mapping.Add("latin5", "latin5");
- mapping.Add("greek", "greek");
- mapping.Add("hebrew", "hebrew");
- mapping.Add("utf8", "utf-8");
- mapping.Add("ucs2", "UTF-16BE");
- mapping.Add("cp1251", "windows-1251");
- mapping.Add("tis620", "windows-874");
- mapping.Add("cp1250", "windows-1250");
- mapping.Add("cp932", "sjis");
- mapping.Add("win1250", "windows-1250");
- mapping.Add("cp1256", "cp1256");
- mapping.Add("latin1_de", "iso-8859-1");
- mapping.Add("german1", "iso-8859-1");
- mapping.Add("danish", "iso-8859-1");
- mapping.Add("czech", "iso-8859-2");
- mapping.Add("hungarian", "iso-8859-2");
- mapping.Add("croat", "iso-8859-2");
- mapping.Add("latin7", "iso-8859-7");
- mapping.Add("latvian", "iso-8859-13");
- mapping.Add("latvian1", "iso-8859-13");
- mapping.Add("estonia", "iso-8859-13");
- mapping.Add("euckr", "euc-kr");
- mapping.Add("euc_kr", "euc-kr");
- mapping.Add("cp866", "cp866");
- mapping.Add("Cp852", "ibm852");
- mapping.Add("Cp850", "ibm850");
- mapping.Add("win1251ukr", "windows-1251");
- mapping.Add("cp1251csas", "windows-1251");
- mapping.Add("cp1251cias", "windows-1251");
- mapping.Add("win1251", "windows-1251");
- mapping.Add("cp1257", "windows-1257");
- mapping.Add("gbk", "gb2312");
- mapping.Add("koi8_ru", "koi8-u");
- mapping.Add("koi8r", "koi8-u");
- mapping.Add("dos", "ibm437");
- mapping.Add("ujis", "EUC-JP");
- mapping.Add("eucjpms", "EUC-JP");
- mapping.Add("ascii", "us-ascii");
- mapping.Add("usa7", "us-ascii");
- mapping.Add("binary", "us-ascii");
- mapping.Add("macroman", "x-mac-romanian");
- mapping.Add("macce", "x-mac-ce");
+ mapping.Add("latin1", new CharacterSet("latin1", 1));
+ mapping.Add("big5", new CharacterSet("big5", 2));
+ mapping.Add("dec8", mapping["latin1"]);
+ mapping.Add("cp850", new CharacterSet("ibm850", 1));
+ mapping.Add("hp8", mapping["latin1"]);
+ mapping.Add("koi8r", new CharacterSet("koi8-u", 1));
+ mapping.Add("latin2", new CharacterSet("latin2", 1));
+ mapping.Add("swe7", mapping["latin1"]);
+ mapping.Add("ujis", new CharacterSet("EUC-JP", 3));
+ mapping.Add("eucjpms", mapping["ujis"]);
+ mapping.Add("sjis", new CharacterSet("sjis", 2));
+ mapping.Add("cp932", mapping["sjis"]);
+ mapping.Add("hebrew", new CharacterSet("hebrew", 1));
+ mapping.Add("tis620", new CharacterSet("windows-874", 1));
+ mapping.Add("euckr", new CharacterSet("euc-kr", 2));
+ mapping.Add("euc_kr", mapping["euckr"]);
+ mapping.Add("koi8u", new CharacterSet("koi8-u", 1));
+ mapping.Add("koi8_ru", mapping["koi8u"]);
+ mapping.Add("gb2312", new CharacterSet("gb2312", 2));
+ mapping.Add("gbk", mapping["gb2312"]);
+ mapping.Add("greek", new CharacterSet("greek", 1));
+ mapping.Add("cp1250", new CharacterSet("windows-1250", 1));
+ mapping.Add("win1250", mapping["cp1250"]);
+ mapping.Add("latin5", new CharacterSet("latin5", 1));
+ mapping.Add("armscii8", mapping["latin1"]);
+ mapping.Add("utf8", new CharacterSet("utf-8", 3));
+ mapping.Add("ucs2", new CharacterSet("UTF-16BE", 2));
+ mapping.Add("cp866", new CharacterSet("cp866", 1));
+ mapping.Add("keybcs2", mapping["latin1"]);
+ mapping.Add("macce", new CharacterSet("x-mac-ce", 1));
+ mapping.Add("macroman", new CharacterSet("x-mac-romanian", 1));
+ mapping.Add("cp852", new CharacterSet("ibm852", 2));
+ mapping.Add("latin7", new CharacterSet("iso-8859-7", 1));
+ mapping.Add("cp1251", new CharacterSet("windows-1251", 1));
+ mapping.Add("win1251ukr", mapping["cp1251"]);
+ mapping.Add("cp1251csas", mapping["cp1251"]);
+ mapping.Add("cp1251cias", mapping["cp1251"]);
+ mapping.Add("win1251", mapping["cp1251"]);
+ mapping.Add("cp1256", new CharacterSet("cp1256", 1));
+ mapping.Add("cp1257", new CharacterSet("windows-1257", 1));
+ mapping.Add("ascii", new CharacterSet("us-ascii", 1));
+ mapping.Add("usa7", mapping["ascii"]);
+ mapping.Add("binary", mapping["ascii"]);
+ mapping.Add("latin3", new CharacterSet("latin3", 1));
+ mapping.Add("latin4", new CharacterSet("latin4", 1));
+ mapping.Add("latin1_de", new CharacterSet("iso-8859-1", 1));
+ mapping.Add("german1", new CharacterSet("iso-8859-1", 1));
+ mapping.Add("danish", new CharacterSet("iso-8859-1", 1));
+ mapping.Add("czech", new CharacterSet("iso-8859-2", 1));
+ mapping.Add("hungarian", new CharacterSet("iso-8859-2", 1));
+ mapping.Add("croat", new CharacterSet("iso-8859-2", 1));
+ mapping.Add("latvian", new CharacterSet("iso-8859-13", 1));
+ mapping.Add("latvian1", new CharacterSet("iso-8859-13", 1));
+ mapping.Add("estonia", new CharacterSet("iso-8859-13", 1));
+ mapping.Add("dos", new CharacterSet("ibm437", 1));
}
}
+
+ internal class CharacterSet
+ {
+ public string name;
+ public int byteCount;
+
+ public CharacterSet(string name, int byteCount)
+ {
+ this.name = name;
+ this.byteCount = byteCount;
+ }
+ }
}
Modified: branches/1.0/mysqlclient/Field.cs
===================================================================
--- branches/1.0/mysqlclient/Field.cs 2006-10-17 22:41:15 UTC (rev 411)
+++ branches/1.0/mysqlclient/Field.cs 2006-10-18 14:49:09 UTC (rev 412)
@@ -30,62 +30,64 @@
{
internal enum ColumnFlags : int
{
- NOT_NULL = 1,
- PRIMARY_KEY = 2,
- UNIQUE_KEY = 4,
- MULTIPLE_KEY = 8,
- BLOB = 16,
- UNSIGNED = 32,
- ZERO_FILL = 64,
- BINARY = 128,
- ENUM = 256,
- AUTO_INCREMENT = 512,
- TIMESTAMP = 1024,
- SET = 2048,
- NUMBER = 32768
+ NOT_NULL = 1,
+ PRIMARY_KEY = 2,
+ UNIQUE_KEY = 4,
+ MULTIPLE_KEY = 8,
+ BLOB = 16,
+ UNSIGNED = 32,
+ ZERO_FILL = 64,
+ BINARY = 128,
+ ENUM = 256,
+ AUTO_INCREMENT = 512,
+ TIMESTAMP = 1024,
+ SET = 2048,
+ NUMBER = 32768
};
-
+
/// <summary>
/// Summary description for Field.
/// </summary>
- internal class MySqlField
+ internal class MySqlField
{
#region Fields
// public fields
- public string CatalogName;
- public int ColumnLength;
- public string ColumnName;
- public string OriginalColumnName;
- public string TableName;
- public string RealTableName;
- public string DatabaseName;
- public Encoding Encoding;
+ public string CatalogName;
+ public int ColumnLength;
+ public string ColumnName;
+ public string OriginalColumnName;
+ public string TableName;
+ public string RealTableName;
+ public string DatabaseName;
+ public Encoding Encoding;
+ public int maxLength;
// protected fields
- protected ColumnFlags colFlags;
- protected int charSetIndex;
- protected byte precision;
- protected byte scale;
- protected MySqlDbType mySqlDbType;
- protected DBVersion connVersion;
+ protected ColumnFlags colFlags;
+ protected int charSetIndex;
+ protected byte precision;
+ protected byte scale;
+ protected MySqlDbType mySqlDbType;
+ protected DBVersion connVersion;
#endregion
- public MySqlField( DBVersion connVersion )
+ public MySqlField(DBVersion connVersion)
{
this.connVersion = connVersion;
+ maxLength = 1;
}
#region Properties
- public int CharactetSetIndex
+ public int CharactetSetIndex
{
get { return charSetIndex; }
set { charSetIndex = value; }
}
- public MySqlDbType Type
+ public MySqlDbType Type
{
get { return mySqlDbType; }
set { mySqlDbType = value; }
@@ -103,8 +105,14 @@
set { scale = value; }
}
- public ColumnFlags Flags
- {
+ public int MaxLength
+ {
+ get { return maxLength; }
+ set { maxLength = value; }
+ }
+
+ public ColumnFlags Flags
+ {
get { return colFlags; }
set { colFlags = value; }
}
@@ -149,25 +157,25 @@
get { return (colFlags & ColumnFlags.UNSIGNED) > 0; }
}
- public bool IsTextField
- {
- get
- {
- return Type == MySqlDbType.VarString || Type == MySqlDbType.VarChar ||
- ((Type == MySqlDbType.TinyBlob || Type == MySqlDbType.MediumBlob ||
- Type == MySqlDbType.Blob || Type == MySqlDbType.LongBlob) &&
- !IsBinary);
- }
+ public bool IsTextField
+ {
+ get
+ {
+ return Type == MySqlDbType.VarString || Type == MySqlDbType.VarChar ||
+ ((Type == MySqlDbType.TinyBlob || Type == MySqlDbType.MediumBlob ||
+ Type == MySqlDbType.Blob || Type == MySqlDbType.LongBlob) &&
+ !IsBinary);
+ }
- }
+ }
-#endregion
+ #endregion
public MySqlDbType ProviderType()
{
- if (IsUnsigned)
+ if (IsUnsigned)
{
- switch (Type)
+ switch (Type)
{
case MySqlDbType.Byte: return MySqlDbType.UByte;
case MySqlDbType.Int16: return MySqlDbType.UInt16;
@@ -179,7 +187,7 @@
return Type;
}
- public MySqlValue GetValueObject()
+ public MySqlValue GetValueObject()
{
MySqlValue valueObject = MySqlValue.GetMySqlValue(ProviderType(), IsBinary);
return valueObject;
Modified: branches/1.0/mysqlclient/datareader.cs
===================================================================
--- branches/1.0/mysqlclient/datareader.cs 2006-10-17 22:41:15 UTC (rev 411)
+++ branches/1.0/mysqlclient/datareader.cs 2006-10-18 14:49:09 UTC (rev 412)
@@ -33,18 +33,18 @@
public sealed class MySqlDataReader : MarshalByRefObject, IEnumerable, IDataReader, IDisposable, IDataRecord
{
// The DataReader should always be open when returned to the user.
- private bool isOpen = true;
+ private bool isOpen = true;
// Keep track of the results and position
// within the resultset (starts prior to first record).
- private MySqlField[] fields;
- private CommandBehavior commandBehavior;
- private MySqlCommand command;
- private bool canRead;
- private bool hasRows;
- private CommandResult currentResult;
- private int readCount;
- private DataTable schemaTable;
+ private MySqlField[] fields;
+ private CommandBehavior commandBehavior;
+ private MySqlCommand command;
+ private bool canRead;
+ private bool hasRows;
+ private CommandResult currentResult;
+ private int readCount;
+ private DataTable schemaTable;
/*
* Keep track of the connection in order to implement the
@@ -69,17 +69,17 @@
/// Gets a value indicating the depth of nesting for the current row. This method is not
/// supported currently and always returns 0.
/// </summary>
- public int Depth
+ public int Depth
{
- get { return 0; }
+ get { return 0; }
}
- internal CommandBehavior Behavior
+ internal CommandBehavior Behavior
{
get { return commandBehavior; }
}
- internal CommandResult CurrentResult
+ internal CommandResult CurrentResult
{
get { return currentResult; }
}
@@ -89,10 +89,10 @@
/// </summary>
public bool IsClosed
{
- get { return ! isOpen; }
+ get { return !isOpen; }
}
- void IDisposable.Dispose()
+ void IDisposable.Dispose()
{
if (isOpen)
Close();
@@ -101,7 +101,7 @@
/// <summary>
/// Gets the number of rows changed, inserted, or deleted by execution of the SQL statement.
/// </summary>
- public int RecordsAffected
+ public int RecordsAffected
{
// RecordsAffected returns the number of rows affected in batch
// statments from insert/delete/update statments. This property
@@ -122,9 +122,9 @@
/// </summary>
public void Close()
{
- if (! isOpen) return;
+ if (!isOpen) return;
- try
+ try
{
// finish any current command
if (currentResult != null)
@@ -133,12 +133,12 @@
connection.Reader = null;
command.Consume();
- // if our batch resulted in warnings, then report them now
- // this is suboptimal but we have to report them here since
- // pulling warnings from the server requires a reader and
- // we can't have more than one reader open at one time.
- if (connection.driver.HasWarnings)
- connection.driver.ReportWarnings();
+ // if our batch resulted in warnings, then report them now
+ // this is suboptimal but we have to report them here since
+ // pulling warnings from the server requires a reader and
+ // we can't have more than one reader open at one time.
+ if (connection.driver.HasWarnings)
+ connection.driver.ReportWarnings();
if (0 != (commandBehavior & CommandBehavior.CloseConnection))
connection.Close();
@@ -152,7 +152,7 @@
}
throw;
}
- finally
+ finally
{
isOpen = false;
}
@@ -169,8 +169,8 @@
// Return the count of the number of columns, which in
// this case is the size of the column metadata
// array.
- get
- {
+ get
+ {
if (fields != null)
return fields.Length;
return 0;
@@ -181,7 +181,7 @@
/// Overloaded. Gets the value of a column in its native format.
/// In C#, this property is the indexer for the MySqlDataReader class.
/// </summary>
- public object this [ int i ]
+ public object this[int i]
{
get { return GetValue(i); }
}
@@ -190,7 +190,7 @@
/// Gets the value of a column in its native format.
/// [C#] In C#, this property is the indexer for the MySqlDataReader class.
/// </summary>
- public object this [ String name ]
+ public object this[String name]
{
// Look up the ordinal and return
// the value at that position.
@@ -234,35 +234,35 @@
/// <include file='docs/MySqlDataReader.xml' path='MyDocs/MyMembers[@name="GetBytes"]/*'/>
public long GetBytes(int i, long dataIndex, byte[] buffer, int bufferIndex, int length)
{
- if (i >= fields.Length)
+ if (i >= fields.Length)
throw new IndexOutOfRangeException();
MySqlValue val = GetFieldValue(i, false);
- if (! (val is MySqlBinary))
+ if (!(val is MySqlBinary))
throw new MySqlException("GetBytes can only be called on binary columns");
MySqlBinary binary = (MySqlBinary)val;
- if (buffer == null)
+ if (buffer == null)
return (long)binary.Value.Length;
if (bufferIndex >= buffer.Length || bufferIndex < 0)
throw new IndexOutOfRangeException("Buffer index must be a valid index in buffer");
if (buffer.Length < (bufferIndex + length))
- throw new ArgumentException("Buffer is not large enough to hold the requested data" );
- if (dataIndex < 0 ||
+ throw new ArgumentException("Buffer is not large enough to hold the requested data");
+ if (dataIndex < 0 ||
((ulong)dataIndex >= (ulong)binary.Value.Length && (ulong)binary.Value.Length > 0))
- throw new IndexOutOfRangeException("Data index must be a valid index in the field" );
+ throw new IndexOutOfRangeException("Data index must be a valid index in the field");
- byte[] bytes = (byte[])binary.Value;
+ byte[] bytes = (byte[])binary.Value;
// adjust the length so we don't run off the end
- if ( (ulong)binary.Value.Length < (ulong)(dataIndex+length))
+ if ((ulong)binary.Value.Length < (ulong)(dataIndex + length))
{
length = (int)((ulong)binary.Value.Length - (ulong)dataIndex);
}
- Array.Copy( bytes, (int)dataIndex, buffer, (int)bufferIndex, (int)length );
+ Array.Copy(bytes, (int)dataIndex, buffer, (int)bufferIndex, (int)length);
return length;
}
@@ -289,7 +289,7 @@
/// <returns></returns>
public long GetChars(int i, long fieldOffset, char[] buffer, int bufferoffset, int length)
{
- if (i >= fields.Length)
+ if (i >= fields.Length)
throw new IndexOutOfRangeException();
string valAsString = GetString(i);
@@ -299,13 +299,13 @@
if (bufferoffset >= buffer.Length || bufferoffset < 0)
throw new IndexOutOfRangeException("Buffer index must be a valid index in buffer");
if (buffer.Length < (bufferoffset + length))
- throw new ArgumentException( "Buffer is not large enough to hold the requested data" );
- if (fieldOffset < 0 || fieldOffset >= valAsString.Length )
- throw new IndexOutOfRangeException( "Field offset must be a valid index in the field" );
-
+ throw new ArgumentException("Buffer is not large enough to hold the requested data");
+ if (fieldOffset < 0 || fieldOffset >= valAsString.Length)
+ throw new IndexOutOfRangeException("Field offset must be a valid index in the field");
+
if (valAsString.Length < length)
length = valAsString.Length;
- valAsString.CopyTo( (int)fieldOffset, buffer, bufferoffset, length );
+ valAsString.CopyTo((int)fieldOffset, buffer, bufferoffset, length);
return length;
}
@@ -316,7 +316,7 @@
/// <returns></returns>
public String GetDataTypeName(int i)
{
- if (! isOpen) throw new Exception("No current query in data reader");
+ if (!isOpen) throw new Exception("No current query in data reader");
if (i >= fields.Length) throw new IndexOutOfRangeException();
// return the name of the type used on the backend
@@ -375,15 +375,15 @@
/// <returns></returns>
public Type GetFieldType(int i)
{
- if (! isOpen) throw new Exception("No current query in data reader");
+ if (!isOpen) throw new Exception("No current query in data reader");
if (i >= fields.Length) throw new IndexOutOfRangeException();
- if (currentResult[i] is MySqlDateTime)
- {
- if (!connection.Settings.AllowZeroDateTime)
- return typeof(DateTime);
- return typeof(MySqlDateTime);
- }
+ if (currentResult[i] is MySqlDateTime)
+ {
+ if (!connection.Settings.AllowZeroDateTime)
+ return typeof(DateTime);
+ return typeof(MySqlDateTime);
+ }
return currentResult[i].SystemType;
}
@@ -400,7 +400,7 @@
/// <include file='docs/MySqlDataReader.xml' path='docs/GetGuid/*'/>
public Guid GetGuid(int index)
{
- return new Guid( GetString(index) );
+ return new Guid(GetString(index));
}
/// <include file='docs/MySqlDataReader.xml' path='docs/GetInt16/*'/>
@@ -447,11 +447,11 @@
/// <returns></returns>
public int GetOrdinal(string name)
{
- if (! isOpen)
+ if (!isOpen)
throw new Exception("No current query in data reader");
name = name.ToLower(System.Globalization.CultureInfo.InvariantCulture);
- for (int i=0; i < fields.Length; i ++)
+ for (int i = 0; i < fields.Length; i++)
{
if (fields[i].ColumnName.ToLower(System.Globalization.CultureInfo.InvariantCulture) == name)
return i;
@@ -474,46 +474,42 @@
// otherwise, DataTable is null reference
if (fields.Length == 0) return null;
- DataTable dataTableSchema = new DataTable ("SchemaTable");
-
- dataTableSchema.Columns.Add ("ColumnName", typeof (string));
- dataTableSchema.Columns.Add ("ColumnOrdinal", typeof (int));
- dataTableSchema.Columns.Add ("ColumnSize", typeof (int));
- dataTableSchema.Columns.Add ("NumericPrecision", typeof (int));
- dataTableSchema.Columns.Add ("NumericScale", typeof (int));
- dataTableSchema.Columns.Add ("IsUnique", typeof (bool));
- dataTableSchema.Columns.Add ("IsKey", typeof (bool));
+ DataTable dataTableSchema = new DataTable("SchemaTable");
+
+ dataTableSchema.Columns.Add("ColumnName", typeof(string));
+ dataTableSchema.Columns.Add("ColumnOrdinal", typeof(int));
+ dataTableSchema.Columns.Add("ColumnSize", typeof(int));
+ dataTableSchema.Columns.Add("NumericPrecision", typeof(int));
+ dataTableSchema.Columns.Add("NumericScale", typeof(int));
+ dataTableSchema.Columns.Add("IsUnique", typeof(bool));
+ dataTableSchema.Columns.Add("IsKey", typeof(bool));
DataColumn dc = dataTableSchema.Columns["IsKey"];
dc.AllowDBNull = true; // IsKey can have a DBNull
- dataTableSchema.Columns.Add ("BaseCatalogName", typeof (string));
- dataTableSchema.Columns.Add ("BaseColumnName", typeof (string));
- dataTableSchema.Columns.Add ("BaseSchemaName", typeof (string));
- dataTableSchema.Columns.Add ("BaseTableName", typeof (string));
- dataTableSchema.Columns.Add ("DataType", typeof(Type));
- dataTableSchema.Columns.Add ("AllowDBNull", typeof (bool));
- dataTableSchema.Columns.Add ("ProviderType", typeof (int));
- dataTableSchema.Columns.Add ("IsAliased", typeof (bool));
- dataTableSchema.Columns.Add ("IsExpression", typeof (bool));
- dataTableSchema.Columns.Add ("IsIdentity", typeof (bool));
- dataTableSchema.Columns.Add ("IsAutoIncrement", typeof (bool));
- dataTableSchema.Columns.Add ("IsRowVersion", typeof (bool));
- dataTableSchema.Columns.Add ("IsHidden", typeof (bool));
- dataTableSchema.Columns.Add ("IsLong", typeof (bool));
- dataTableSchema.Columns.Add ("IsReadOnly", typeof (bool));
+ dataTableSchema.Columns.Add("BaseCatalogName", typeof(string));
+ dataTableSchema.Columns.Add("BaseColumnName", typeof(string));
+ dataTableSchema.Columns.Add("BaseSchemaName", typeof(string));
+ dataTableSchema.Columns.Add("BaseTableName", typeof(string));
+ dataTableSchema.Columns.Add("DataType", typeof(Type));
+ dataTableSchema.Columns.Add("AllowDBNull", typeof(bool));
+ dataTableSchema.Columns.Add("ProviderType", typeof(int));
+ dataTableSchema.Columns.Add("IsAliased", typeof(bool));
+ dataTableSchema.Columns.Add("IsExpression", typeof(bool));
+ dataTableSchema.Columns.Add("IsIdentity", typeof(bool));
+ dataTableSchema.Columns.Add("IsAutoIncrement", typeof(bool));
+ dataTableSchema.Columns.Add("IsRowVersion", typeof(bool));
+ dataTableSchema.Columns.Add("IsHidden", typeof(bool));
+ dataTableSchema.Columns.Add("IsLong", typeof(bool));
+ dataTableSchema.Columns.Add("IsReadOnly", typeof(bool));
int ord = 1;
- for (int i=0; i < fields.Length; i++)
+ for (int i = 0; i < fields.Length; i++)
{
MySqlField f = fields[i];
DataRow r = dataTableSchema.NewRow();
r["ColumnName"] = f.ColumnName;
r["ColumnOrdinal"] = ord++;
- int maxByteCount = f.Encoding.GetMaxByteCount(1);
-#if NET20
- maxByteCount >>= 1;
-#endif
- r["ColumnSize"] = f.IsTextField ? f.ColumnLength / maxByteCount : f.ColumnLength;
+ r["ColumnSize"] = f.IsTextField ? f.ColumnLength / f.MaxLength : f.ColumnLength;
int prec = f.Precision;
int pscale = f.Scale;
if (prec != -1)
@@ -534,7 +530,7 @@
r["BaseTableName"] = f.RealTableName;
r["BaseColumnName"] = f.OriginalColumnName;
- dataTableSchema.Rows.Add( r );
+ dataTableSchema.Rows.Add(r);
}
schemaTable = dataTableSchema;
@@ -566,7 +562,7 @@
/// <returns></returns>
public object GetValue(int i)
{
- if (! isOpen) throw new Exception("No current query in data reader");
+ if (!isOpen) throw new Exception("No current query in data reader");
if (i >= fields.Length) throw new IndexOutOfRangeException();
MySqlValue val = GetFieldValue(i, false);
@@ -574,12 +570,12 @@
// if the column is a date/time, then we return a MySqlDateTime
// so .ToString() will print '0000-00-00' correctly
- if (val is MySqlDateTime)
+ if (val is MySqlDateTime)
{
MySqlDateTime dt = (MySqlDateTime)val;
- if (! dt.IsValidDateTime && connection.Settings.ConvertZeroDateTime)
+ if (!dt.IsValidDateTime && connection.Settings.ConvertZeroDateTime)
return DateTime.MinValue;
- else if (connection.Settings.AllowZeroDateTime)
+ else if (connection.Settings.AllowZeroDateTime)
return val;
else
return dt.GetDateTime();
@@ -596,15 +592,15 @@
public int GetValues(object[] values)
{
if (values == null) return 0;
- int numCols = Math.Min( values.Length, fields.Length );
- for (int i=0; i < numCols; i ++)
+ int numCols = Math.Min(values.Length, fields.Length);
+ for (int i = 0; i < numCols; i++)
values[i] = GetValue(i);
return numCols;
}
/// <include file='docs/MySqlDataReader.xml' path='docs/GetUInt16/*'/>
- public UInt16 GetUInt16( int index )
+ public UInt16 GetUInt16(int index)
{
MySqlValue v = GetFieldValue(index, true);
if (v is MySqlUInt16)
@@ -613,7 +609,7 @@
}
/// <include file='docs/MySqlDataReader.xml' path='docs/GetUInt32/*'/>
- public UInt32 GetUInt32( int index )
+ public UInt32 GetUInt32(int index)
{
MySqlValue v = GetFieldValue(index, true);
if (v is MySqlUInt32)
@@ -622,7 +618,7 @@
}
/// <include file='docs/MySqlDataReader.xml' path='docs/GetUInt64/*'/>
- public UInt64 GetUInt64( int index )
+ public UInt64 GetUInt64(int index)
{
MySqlValue v = GetFieldValue(index, true);
if (v is MySqlUInt64)
@@ -654,21 +650,21 @@
/// <returns></returns>
public bool NextResult()
{
- if (! isOpen)
+ if (!isOpen)
throw new MySqlException("Invalid attempt to NextResult when reader is closed.");
// clear any rows that have not been read from the last rowset
- if (currentResult != null)
+ if (currentResult != null)
currentResult.Consume();
// tell our command to continue execution of the SQL batch until it its
// another resultset
- try
+ try
{
CommandResult nextResult = command.GetNextResultSet(this);
if (nextResult != null)
currentResult = nextResult;
- else
+ else
{
// if there was no more resultsets, then signal done
canRead = false;
@@ -681,7 +677,7 @@
// When executing query statements, the result byte that is returned
// from MySql is the column count. That is why we reference the LastResult
// property here to dimension our field array
- connection.SetState( ConnectionState.Fetching );
+ connection.SetState(ConnectionState.Fetching);
// load in our field defs and set our internal variables so we know
// what we can do (canRead, hasRows)
@@ -689,18 +685,18 @@
fields = currentResult.Fields;
return true;
}
- catch (Exception ex)
+ catch (Exception ex)
{
if (ex is MySqlException && !(ex as MySqlException).IsFatal)
- connection.SetState( ConnectionState.Open );
+ connection.SetState(ConnectionState.Open);
else
connection.Terminate();
throw;
}
- finally
+ finally
{
if (connection.State != ConnectionState.Closed && connection.State != ConnectionState.Open)
- connection.SetState( ConnectionState.Open );
+ connection.SetState(ConnectionState.Open);
}
}
@@ -710,27 +706,27 @@
/// <returns></returns>
public bool Read()
{
- if (! isOpen)
+ if (!isOpen)
throw new MySqlException("Invalid attempt to Read when reader is closed.");
- if (! canRead) return false;
- readCount ++;
+ if (!canRead) return false;
+ readCount++;
- connection.SetState( ConnectionState.Fetching );
+ connection.SetState(ConnectionState.Fetching);
- try
+ try
{
- try
+ try
{
- if ( (Behavior & CommandBehavior.SequentialAccess) != 0)
- canRead = currentResult.ReadDataRow( false );
+ if ((Behavior & CommandBehavior.SequentialAccess) != 0)
+ canRead = currentResult.ReadDataRow(false);
else
- canRead = currentResult.ReadDataRow( true );
- if ( ! canRead) return false;
+ canRead = currentResult.ReadDataRow(true);
+ if (!canRead) return false;
}
- catch (MySqlException ex)
+ catch (MySqlException ex)
{
- if (ex.IsFatal)
+ if (ex.IsFatal)
connection.Terminate();
throw;
}
@@ -745,24 +741,24 @@
System.Diagnostics.Trace.WriteLine("MySql error: " + ex.Message);
throw;
}
- finally
+ finally
{
- connection.SetState( ConnectionState.Open );
+ connection.SetState(ConnectionState.Open);
}
return true;
}
- private MySqlValue GetFieldValue(int index, bool checkNull)
+ private MySqlValue GetFieldValue(int index, bool checkNull)
{
- if (index < 0 || index >= fields.Length)
- throw new ArgumentException( "You have specified an invalid column ordinal." );
+ if (index < 0 || index >= fields.Length)
+ throw new ArgumentException("You have specified an invalid column ordinal.");
try
{
MySqlValue val = currentResult.ReadColumnValue(index);
- if (val.IsNull && checkNull)
- throw new SqlNullValueException();
+ if (val.IsNull && checkNull)
+ throw new SqlNullValueException();
if (readCount == 0)
throw new MySqlException("Invalid attempt to access a field before calling Read()");
@@ -782,7 +778,7 @@
#region IEnumerator
- IEnumerator IEnumerable.GetEnumerator()
+ IEnumerator IEnumerable.GetEnumerator()
{
return new System.Data.Common.DbEnumerator(this);
}
Modified: branches/1.0/mysqlclient/nativedriver.cs
===================================================================
--- branches/1.0/mysqlclient/nativedriver.cs 2006-10-17 22:41:15 UTC (rev 411)
+++ branches/1.0/mysqlclient/nativedriver.cs 2006-10-18 14:49:09 UTC (rev 412)
@@ -565,7 +565,11 @@
field.Scale = (byte)reader.ReadByte();
if (charSets != null)
- field.Encoding = CharSetMap.GetEncoding( this.version, (string)charSets[field.CharactetSetIndex] );
+ {
+ CharacterSet cs = CharSetMap.GetChararcterSet(this.Version, (string)charSets[field.CharactetSetIndex]);
+ field.MaxLength = cs.byteCount;
+ field.Encoding = CharSetMap.GetEncoding(this.version, (string)charSets[field.CharactetSetIndex]);
+ }
return field;
}
| Thread |
|---|
| • Connector/NET commit: r412 - in branches/1.0: TestSuite mysqlclient | rburnett | 18 Oct |