ソースを参照

Added missing 'using' statements.

svn path=/trunk/mcs/; revision=65344
Leszek 'skolima' Ciesielski 19 年 前
コミット
8a487c2183

+ 6 - 0
mcs/class/System.Data.OracleClient/Test/System.Data.OracleClient/OracleCommandTest.cs

@@ -47,6 +47,12 @@ namespace MonoTests.System.Data.OracleClient {
                         interface_command = command;
                 }
 
+                [TearDown]
+                public void TearDown ()
+                {
+                        command.Dispose ();
+                }
+
                 [Test] // regression for bug #78765
                 public void AllowNullConnectionTest ()
                 {

+ 47 - 45
mcs/class/System.Data.OracleClient/Test/System.Data.OracleClient/OracleLobTest.cs

@@ -58,20 +58,22 @@ namespace MonoTests.System.Data.OracleClient {
                 {
                         connection = new OracleConnection (connection_string);
                         connection.Open ();
-                        command = connection.CreateCommand ();
 
-                        // create the tables
-                        command.CommandText =
-                                        "create table lob_test (id number(10), lobo blob)";
-                        command.ExecuteNonQuery ();
+                        using (command = connection.CreateCommand ()) {
+                                // create the tables
+                                command.CommandText =
+                                                "create table lob_test (id number(10), lobo blob)";
+                                command.ExecuteNonQuery ();
+                        }
                 }
 
                 [TearDown]
                 public void TearDown ()
                 {
-                        command = connection.CreateCommand ();
-                        command.CommandText = "drop table lob_test";
-                        command.ExecuteNonQuery ();
+                        using (command = connection.CreateCommand ()) {
+                                command.CommandText = "drop table lob_test";
+                                command.ExecuteNonQuery ();
+                        }
 
                         connection.Close ();
                         connection.Dispose ();
@@ -80,47 +82,47 @@ namespace MonoTests.System.Data.OracleClient {
                 [Test] // regression for bug #78898
                 public void PositionIs0BasedTest ()
                 {
-                        command = connection.CreateCommand (); // reusing command from SetUp causes parameter names mismatch
+                        using (command = connection.CreateCommand ()) { // reusing command from SetUp causes parameter names mismatch
+                                // insert test values
+                                command.CommandText =
+                                                "insert into lob_test (id, lobo) values (11, '00000000000000000000000000000')";
+                                command.ExecuteNonQuery ();
 
-                        // insert test values
-                        command.CommandText =
-                                        "insert into lob_test (id, lobo) values (11, '00000000000000000000000000000')";
-                        command.ExecuteNonQuery ();
+                                // select for writing test values
+                                command.CommandText =
+                                                "select lobo from lob_test where id = 11 for update";
 
-                        // select for writing test values
-                        command.CommandText =
-                                        "select lobo from lob_test where id = 11 for update";
-
-                        using (OracleDataReader reader = command.ExecuteReader ()) {
-                                if (reader.Read ()) {
-                                        OracleLob lob = reader.GetOracleLob (0);
-                                        Assert.AreEqual (0, lob.Position, "Lob index is not 0 - based.");
-                                        lob.Seek (1, SeekOrigin.Current);
-                                        Assert.AreEqual (1, lob.Position, "Lob seek placed position wrongly.");
-                                        lob.Seek (0, SeekOrigin.End);
-                                        Assert.AreEqual (lob.Length , lob.Position, "Lob end is too far away.");
-                                        TrySeek (lob, -lob.Length, SeekOrigin.End, 0, 1);
-                                        TrySeek (lob, -lob.Length + 5, SeekOrigin.End, 5, 2);
-                                        try {
-                                                lob.Seek (5, SeekOrigin.End);
-                                                Assert.Fail ("Illegal seek succeeded.");
+                                using (OracleDataReader reader = command.ExecuteReader ()) {
+                                        if (reader.Read ()) {
+                                                OracleLob lob = reader.GetOracleLob (0);
+                                                Assert.AreEqual (0, lob.Position, "Lob index is not 0 - based.");
+                                                lob.Seek (1, SeekOrigin.Current);
+                                                Assert.AreEqual (1, lob.Position, "Lob seek placed position wrongly.");
+                                                lob.Seek (0, SeekOrigin.End);
+                                                Assert.AreEqual (lob.Length , lob.Position, "Lob end is too far away.");
+                                                TrySeek (lob, -lob.Length, SeekOrigin.End, 0, 1);
+                                                TrySeek (lob, -lob.Length + 5, SeekOrigin.End, 5, 2);
+                                                try {
+                                                        lob.Seek (5, SeekOrigin.End);
+                                                        Assert.Fail ("Illegal seek succeeded.");
+                                                }
+                                                catch (ArgumentOutOfRangeException) { // exception is required
+                                                }
+                                                lob.Seek (lob.Length - 5, SeekOrigin.Begin);
+                                                Assert.AreEqual (lob.Length - 5 , lob.Position, "Lob position has unexpected value.");
+                                                lob.Seek (0, SeekOrigin.Begin);
+                                                TryRead (lob, 10, 1);
+                                                lob.Seek (5, SeekOrigin.Begin);
+                                                lob.Position = 0;
+                                                TryRead (lob, 10, 2);
+                                                lob.Position = lob.Length;
+                                                TryRead (lob, 0, 3);
+                                                lob.Seek (-1, SeekOrigin.Current);
+                                                TryRead (lob, 1, 4);
                                         }
-                                        catch (ArgumentOutOfRangeException) { // exception is required
+                                        else {
+                                                Assert.Fail ("Expected records not found.");
                                         }
-                                        lob.Seek (lob.Length - 5, SeekOrigin.Begin);
-                                        Assert.AreEqual (lob.Length - 5 , lob.Position, "Lob position has unexpected value.");
-                                        lob.Seek (0, SeekOrigin.Begin);
-                                        TryRead (lob, 10, 1);
-                                        lob.Seek (5, SeekOrigin.Begin);
-                                        lob.Position = 0;
-                                        TryRead (lob, 10, 2);
-                                        lob.Position = lob.Length;
-                                        TryRead (lob, 0, 3);
-                                        lob.Seek (-1, SeekOrigin.Current);
-                                        TryRead (lob, 1, 4);
-                                }
-                                else {
-                                        Assert.Fail ("Expected records not found.");
                                 }
                         }
                 }

+ 77 - 73
mcs/class/System.Data.OracleClient/Test/System.Data.OracleClient/OracleParameterTest.cs

@@ -61,26 +61,27 @@ namespace MonoTests.System.Data.OracleClient {
                 {
                         connection = new OracleConnection (connection_string);
                         connection.Open ();
-                        command = connection.CreateCommand ();
-
-                        // create the tables
-                        command.CommandText =
-                                        "create table oratest (id number(10), text varchar2(64), text2 varchar2(64) )";
-                        command.ExecuteNonQuery ();
-                        
-                        command.CommandText =
-                                        "create table culture_test (id number(10), value1 float, value2 number(20,10))";
-                        command.ExecuteNonQuery ();
+                        using (command = connection.CreateCommand ()) {
+                                // create the tables
+                                command.CommandText =
+                                                "create table oratest (id number(10), text varchar2(64), text2 varchar2(64) )";
+                                command.ExecuteNonQuery ();
+
+                                command.CommandText =
+                                                "create table culture_test (id number(10), value1 float, value2 number(20,10))";
+                                command.ExecuteNonQuery ();
+                        }
                 }
 
                 [TearDown]
                 public void TearDown ()
                 {
-                        command = connection.CreateCommand ();
-                        command.CommandText = "drop table oratest";
-                        command.ExecuteNonQuery ();
-                        command.CommandText = "drop table culture_test";
-                        command.ExecuteNonQuery ();
+                        using (command = connection.CreateCommand ()) {
+                                command.CommandText = "drop table oratest";
+                                command.ExecuteNonQuery ();
+                                command.CommandText = "drop table culture_test";
+                                command.ExecuteNonQuery ();
+                        }
 
                         connection.Close ();
                         connection.Dispose ();
@@ -89,28 +90,29 @@ namespace MonoTests.System.Data.OracleClient {
                 [Test] // regression for bug #78509
                 public void TrimsTrailingSpacesTest ()
                 {
-                        command = connection.CreateCommand (); // reusing command from SetUp causes parameter names mismatch
-
-                        // insert test values
-                        command.CommandText =
-                                        "insert into oratest (id,text,text2) values (:id,:txt,'" + test_value2 + "')";
-                        command.Parameters.Add (new OracleParameter ("ID", OracleType.Int32));
-                        command.Parameters.Add( new OracleParameter ("TXT", OracleType.VarChar));
-                        command.Parameters ["ID"].Value = 100;
-                        command.Parameters ["TXT"].Value = test_value;
-                        command.ExecuteNonQuery ();
-
-                        // read test values
-                        command.CommandText =
-                                        "select text,text2 from oratest where id = 100";
-                        command.Parameters.Clear ();
-                        using (OracleDataReader reader = command.ExecuteReader ()) {
-                                if (reader.Read ()) {
-                                        Assert.AreEqual (test_value2, reader.GetString (1), "Directly passed value mismatched");
-                                        Assert.AreEqual (test_value, reader.GetString (0), "Passed through bind value mismatched");
-                                }
-                                else {
-                                        Assert.Fail ("Expected records not found.");
+                        using (command = connection.CreateCommand ()) { // reusing command from SetUp causes parameter names mismatch
+
+                                // insert test values
+                                command.CommandText =
+                                                "insert into oratest (id,text,text2) values (:id,:txt,'" + test_value2 + "')";
+                                command.Parameters.Add (new OracleParameter ("ID", OracleType.Int32));
+                                command.Parameters.Add( new OracleParameter ("TXT", OracleType.VarChar));
+                                command.Parameters ["ID"].Value = 100;
+                                command.Parameters ["TXT"].Value = test_value;
+                                command.ExecuteNonQuery ();
+
+                                // read test values
+                                command.CommandText =
+                                                "select text,text2 from oratest where id = 100";
+                                command.Parameters.Clear ();
+                                using (OracleDataReader reader = command.ExecuteReader ()) {
+                                        if (reader.Read ()) {
+                                                Assert.AreEqual (test_value2, reader.GetString (1), "Directly passed value mismatched");
+                                                Assert.AreEqual (test_value, reader.GetString (0), "Passed through bind value mismatched");
+                                        }
+                                        else {
+                                                Assert.Fail ("Expected records not found.");
+                                        }
                                 }
                         }
                 }
@@ -131,56 +133,58 @@ namespace MonoTests.System.Data.OracleClient {
                         Thread.CurrentThread.CurrentCulture = new CultureInfo ("ja-JP", false);
                         CultureSensitiveNumbersInsertTest (3);
                         CultureSensitiveNumbersSelectTest (3);
-                        
+
                         Thread.CurrentThread.CurrentCulture = currentCulture;
                 }
 
                 // regression for bug #79284
                 protected void CultureSensitiveNumbersInsertTest (int id)
                 {
-                        command = connection.CreateCommand (); // reusing command from SetUp causes parameter names mismatch
-                        // insert test values
-                        command.CommandText =
-                                        "insert into culture_test (id,value1,value2) values (:id,:value1,:value2)";
-                        command.Parameters.Add (new OracleParameter ("ID", OracleType.Int32));
-                        command.Parameters.Add( new OracleParameter ("VALUE1", OracleType.Float));
-                        command.Parameters.Add( new OracleParameter ("VALUE2", OracleType.Double));
-                        command.Parameters ["ID"].Value = id;
-                        command.Parameters ["VALUE1"].Value = 2346.2342f;
-                        command.Parameters ["VALUE2"].Value = 4567456.23412m;
-                        try {
-                                command.ExecuteNonQuery ();
-                        }
-                        catch (OracleException e) {
-                                if (e.Code == 1722)
-                                        Assert.Fail("Culture incompatibility error while inserting [" + id + ']');
-                                else throw;
+                        using (command = connection.CreateCommand ()) { // reusing command from SetUp causes parameter names mismatch
+                                // insert test values
+                                command.CommandText =
+                                                "insert into culture_test (id,value1,value2) values (:id,:value1,:value2)";
+                                command.Parameters.Add (new OracleParameter ("ID", OracleType.Int32));
+                                command.Parameters.Add( new OracleParameter ("VALUE1", OracleType.Float));
+                                command.Parameters.Add( new OracleParameter ("VALUE2", OracleType.Double));
+                                command.Parameters ["ID"].Value = id;
+                                command.Parameters ["VALUE1"].Value = 2346.2342f;
+                                command.Parameters ["VALUE2"].Value = 4567456.23412m;
+                                try {
+                                        command.ExecuteNonQuery ();
+                                }
+                                catch (OracleException e) {
+                                        if (e.Code == 1722)
+                                                Assert.Fail("Culture incompatibility error while inserting [" + id + ']');
+                                        else throw;
+                                }
                         }
                 }
 
                 // regression for bug #79284
                 protected void CultureSensitiveNumbersSelectTest (int id)
                 {
-                        command = connection.CreateCommand (); // reusing command from SetUp causes parameter names mismatch
-                        // read test values
-                        command.CommandText =
-                                        "select value1,value2 from culture_test where id = " + id;
-                        command.Parameters.Clear ();
-                        try {
-                                using (OracleDataReader reader = command.ExecuteReader ()) {
-                                        if (reader.Read ()) {
-                                                Assert.AreEqual (2346.2342f,reader.GetFloat(0),
-                                                        "Float value improperly stored [" + id + ']');
-                                                Assert.AreEqual (4567456.23412m, reader.GetDecimal (1),
-                                                        "Decimal value improperly stored [" + id + ']');
-                                        }
-                                        else {
-                                                Assert.Fail ("Expected records not found [" + id + ']');
+                        using (command = connection.CreateCommand ()) { // reusing command from SetUp causes parameter names mismatch
+                                // read test values
+                                command.CommandText =
+                                                "select value1,value2 from culture_test where id = " + id;
+                                command.Parameters.Clear ();
+                                try {
+                                        using (OracleDataReader reader = command.ExecuteReader ()) {
+                                                if (reader.Read ()) {
+                                                        Assert.AreEqual (2346.2342f,reader.GetFloat(0),
+                                                                "Float value improperly stored [" + id + ']');
+                                                        Assert.AreEqual (4567456.23412m, reader.GetDecimal (1),
+                                                                "Decimal value improperly stored [" + id + ']');
+                                                }
+                                                else {
+                                                        Assert.Fail ("Expected records not found [" + id + ']');
+                                                }
                                         }
                                 }
-                        }
-                        catch (FormatException) {
-                                Assert.Fail("Culture incompatibility error while reading [" + id + ']');
+                                catch (FormatException) {
+                                        Assert.Fail("Culture incompatibility error while reading [" + id + ']');
+                                }
                         }
                 }
         }