Przeglądaj źródła

2009-06-03 Veerapuram Varadhan <[email protected]>

	* OracleParameter.cs:  If a non-zero size is passed, update
	the size member but sizeSet is updated only when a non-null
	value is passed.

svn path=/trunk/mcs/; revision=135234
Veerapuram Varadhan 16 lat temu
rodzic
commit
dcd2eb9f91

+ 7 - 1
mcs/class/System.Data.OracleClient/System.Data.OracleClient/ChangeLog

@@ -1,4 +1,10 @@
-2009-09-15  Veerapuram Varadhan  <[email protected]>
+2009-06-03  Veerapuram Varadhan  <[email protected]>
+	
+	* OracleParameter.cs:  If a non-zero size is passed, update 
+	the size member but sizeSet is updated only when a non-null 
+	value is passed.
+	
+2009-05-15  Veerapuram Varadhan  <[email protected]>
 
 	* OracleParameter.cs: Consider DBNull.Value as null and 
 	update size and sizeSet accordingly.

+ 9 - 6
mcs/class/System.Data.OracleClient/System.Data.OracleClient/OracleParameter.cs

@@ -155,10 +155,11 @@ namespace System.Data.OracleClient
 				throw new ArgumentException("Size must be not be negative.");
 			
 			this.value = value;
-			if (value != null && value != DBNull.Value) {
-				this.size = size;
+			this.size = size;
+			// set sizeSet to true iff value is not-null or non-zero size value
+			if (value != null && value != DBNull.Value && size > 0)
 				this.sizeSet = true;
-			}
+
 			SourceColumnNullMapping = sourceColumnNullMapping;
 			OracleType = oracleType;
 			Direction = direction;
@@ -174,10 +175,12 @@ namespace System.Data.OracleClient
 				throw new ArgumentException("Size must be not be negative.");
 			
 			this.value = value;
-			if (value != null && value != DBNull.Value) {
-				this.size = size;
+			this.size = size;
+			
+			// set sizeSet to true iff value is not-null or non-zero size value
+			if (value != null && value != DBNull.Value && size > 0)
 				this.sizeSet = true;
-			}
+
 			this.isNullable = isNullable;
 			this.precision = precision;
 			this.scale = scale;

+ 5 - 0
mcs/class/System.Data.OracleClient/Test/System.Data.OracleClient/ChangeLog

@@ -1,3 +1,8 @@
+2009-06-03  Veerapuram Varadhan  <[email protected]>
+
+	* OracleParameterTest.cs: Use the member variables for
+	connection/command for executing the tests.
+	
 2009-05-15  Veerapuram Varadhan  <[email protected]>
 
 	* OracleParameterTest.cs: Added tests corresponding to #424908

+ 94 - 100
mcs/class/System.Data.OracleClient/Test/System.Data.OracleClient/OracleParameterTest.cs

@@ -388,122 +388,116 @@ namespace MonoTests.System.Data.OracleClient
 		    string insertValue = "INSERT INTO oratest VALUES " +
 			"(424608, \"This is a test for 424908 parameter size bug\", NULL);";
 
-		    OracleCommand cmd = new OracleCommand ();
-		    cmd.Connection = conn;
-		    cmd.CommandText = createSP;
-		    cmd.CommandType = CommandType.Text;
-		    cmd.ExecuteNonQuery ();
-
-		    cmd.CommandText = insertValue;
-		    cmd.ExecuteNonQuery ();
-
-		    cmd.CommandText = "commit";
-		    cmd.ExecuteNonQuery ();
-		    cmd.Dispose ();
+		    using (command = conn.CreateCommand ()) {
+			command.CommandText = createSP;
+			command.CommandType = CommandType.Text;
+			command.ExecuteNonQuery ();
+
+			command.CommandText = insertValue;
+			command.ExecuteNonQuery ();
+
+			command.CommandText = "commit";
+			command.ExecuteNonQuery ();
+		    }
 		}
 
 		[Test]
 		public void ParamSize_424908_ValueError ()
 		{
-		    OracleConnection conn = new OracleConnection (connection_string);
-		    conn.Open ();
-
-		    ParamSize_SPCreation_ValueInsertion (conn);
-
-		    OracleCommand cmd = new OracleCommand ();
-		    cmd.Connection = conn;
-
-		    OracleParameter id = new OracleParameter ();
-		    id.ParameterName = "id";
-		    id.OracleType = OracleType.Number;
-		    id.Direction = ParameterDirection.Input;
-		    id.Value = 424908;
-		    cmd.Parameters.Add (id);
-
-		    OracleParameter text = new OracleParameter ();
-		    text.ParameterName = "text";                                                                    
-		    text.OracleType = OracleType.NVarChar;                                                                  
-		    text.Direction = ParameterDirection.Output;
-		    text.Value = string.Empty;
-		    text.Size = 64;
-		    cmd.Parameters.Add (text);
-
-		    try {
-			cmd.CommandType = CommandType.StoredProcedure;
-			cmd.CommandText = "GetTextValue";
-			cmd.ExecuteNonQuery ();
-			Assert.Fail ("Expected OracleException not occurred!");
-		    } catch (OracleException ex) {
-			Assert.AreEqual ("6502", ex.Code, "Error code mismatch");
-			connection.Close ();
+		    //OracleConnection conn = new OracleConnection (connection_string);
+		    //conn.Open ();
+
+		    ParamSize_SPCreation_ValueInsertion (connection);
+
+		    using (command = connection.CreateCommand ()) {
+			
+			OracleParameter id = new OracleParameter ();
+			id.ParameterName = "id";
+			id.OracleType = OracleType.Number;
+			id.Direction = ParameterDirection.Input;
+			id.Value = 424908;
+			command.Parameters.Add (id);
+
+			OracleParameter text = new OracleParameter ();
+			text.ParameterName = "text";                                                                    
+			text.OracleType = OracleType.NVarChar;                                                                  
+			text.Direction = ParameterDirection.Output;
+			text.Value = string.Empty;
+			text.Size = 64;
+			command.Parameters.Add (text);
+
+			try {
+			    command.CommandType = CommandType.StoredProcedure;
+			    command.CommandText = "GetTextValue";
+			    command.ExecuteNonQuery ();
+			    Assert.Fail ("Expected OracleException not occurred!");
+			} catch (OracleException ex) {
+			    Assert.AreEqual ("6502", ex.Code, "Error code mismatch");
+			    connection.Close ();
+			}
 		    }
 		}
 
 		[Test]
 		public void ParamSize_424908_ConstructorSizeSetTest ()
 		{
-		    OracleConnection conn = new OracleConnection (connection_string);
-		    conn.Open ();
-
-		    ParamSize_SPCreation_ValueInsertion (conn);
+		    //OracleConnection conn = new OracleConnection (connection_string);
+		    //conn.Open ();
+
+		    ParamSize_SPCreation_ValueInsertion (connection);
+
+		    using (command = connection.CreateCommand ()) {
+			OracleParameter id = new OracleParameter ();
+			id.ParameterName = "id";
+			id.OracleType = OracleType.Number;
+			id.Direction = ParameterDirection.Input;
+			id.Value = 424908;
+			command.Parameters.Add (id);
+
+			OracleParameter text = new OracleParameter ("text", OracleType.NVarChar, 64);
+			text.Direction = ParameterDirection.Output;
+			text.Value = string.Empty;
+			text.Size = 64;
+			command.Parameters.Add (text);
+
+			command.CommandType = CommandType.StoredProcedure;
+			command.CommandText = "GetTextValue";
+			command.ExecuteNonQuery ();
+
+			Assert.AreEqual ("This is a test for 424908 parameter size bug", text.Value, "OracleParameter value mismatch");
+		    }
+		}
 
-		    OracleCommand cmd = new OracleCommand ();
-		    cmd.Connection = conn;
+		[Test]
+		public void ParamSize_424908_SizeNotSetError ()
+		{
 
-		    OracleParameter id = new OracleParameter ();
-		    id.ParameterName = "id";
-		    id.OracleType = OracleType.Number;
-		    id.Direction = ParameterDirection.Input;
-		    id.Value = 424908;
-		    cmd.Parameters.Add (id);
+		    ParamSize_SPCreation_ValueInsertion (connection);
 
-		    OracleParameter text = new OracleParameter ("text", OracleType.NVarChar, 64);
-		    text.Direction = ParameterDirection.Output;
-		    text.Value = string.Empty;
-		    text.Size = 64;
-		    cmd.Parameters.Add (text);
+		    using (command = connection.CreateCommand ()) {
+			OracleParameter id = new OracleParameter ();
+			id.ParameterName = "id";
+			id.OracleType = OracleType.Number;
+			id.Direction = ParameterDirection.Input;
+			id.Value = 424908;
+			command.Parameters.Add (id);
 
-		    cmd.CommandType = CommandType.StoredProcedure;
-		    cmd.CommandText = "GetTextValue";
-		    cmd.ExecuteNonQuery ();
+			OracleParameter text = new OracleParameter ();
+			text.ParameterName = "text";                                                                    
+			text.OracleType = OracleType.NVarChar;                                                                  
+			text.Direction = ParameterDirection.Output;
+			text.Value = DBNull.Value;
+			command.Parameters.Add (text);
 
-		    Assert.AreEqual ("This is a test for 424908 parameter size bug", text.Value, "OracleParameter value mismatch");
-		    conn.Close ();
-		}
-		[Test]
-		public void ParamSize_424908_SizeNotSetError ()
-		{
-		    OracleConnection conn = new OracleConnection (connection_string);
-		    conn.Open ();
-
-		    ParamSize_SPCreation_ValueInsertion (conn);
-
-		    OracleCommand cmd = new OracleCommand ();
-		    cmd.Connection = conn;
-
-		    OracleParameter id = new OracleParameter ();
-		    id.ParameterName = "id";
-		    id.OracleType = OracleType.Number;
-		    id.Direction = ParameterDirection.Input;
-		    id.Value = 424908;
-		    cmd.Parameters.Add (id);
-
-		    OracleParameter text = new OracleParameter ();
-		    text.ParameterName = "text";                                                                    
-		    text.OracleType = OracleType.NVarChar;                                                                  
-		    text.Direction = ParameterDirection.Output;
-		    text.Value = DBNull.Value;
-		    cmd.Parameters.Add (text);
-
-		    try {
-			cmd.CommandType = CommandType.StoredProcedure;
-			cmd.CommandText = "GetTextValue";
-			cmd.ExecuteNonQuery ();
-			Assert.Fail ("Expected System.Exception not occurred!");
-		    } catch (Exception ex) {
-			conn.Close ();
-			Assert.AreEqual ("Size must be set.", ex.Message, "Exception mismatch");
-		    }		    
+			try {
+			    command.CommandType = CommandType.StoredProcedure;
+			    command.CommandText = "GetTextValue";
+			    command.ExecuteNonQuery ();
+			    Assert.Fail ("Expected System.Exception not occurred!");
+			} catch (Exception ex) {
+			    Assert.AreEqual ("Size must be set.", ex.Message, "Exception mismatch");
+			}		    
+		    }
 		}
 	}
 }