瀏覽代碼

2005-10-27 Senganal T <[email protected]>

* Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds.cs :
- Added a virtual method IsValidRowCount ()
- Modified the way RecordsAffected is being counted

* Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds70.cs :
- Overrode IsValidRowCount(), to check if the rowcount
returned by sqlserver is valid.

* System.Data/Test/ProviderTests/System.Data.SqlClient/SqlCommandTest.cs :
- Added Testcase for bug #75698

* System.Data/System.Data.SqlClient/SqlCommand.cs
* System.Data/System.Data.SqlClient/SqlDataReader.cs :
-Made changes so that the number of rows affected can be got directly
from Tds regardsless of the type of query.Fixes bug #75698

svn path=/trunk/mcs/; revision=52268

Senganal T 20 年之前
父節點
當前提交
a34e1cf63d

+ 10 - 0
mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/ChangeLog

@@ -1,3 +1,13 @@
+2005-10-27  Senganal T  <[email protected]>
+	
+	* Tds.cs :
+		- Added a virtual method IsValidRowCount ()
+		- Modified the way RecordsAffected is being counted
+
+	* Tds70.cs :
+		- Overrode IsValidRowCount(), to check if the rowcount
+		returned by sqlserver is valid.
+
 2005-10-19  Senganal T  <[email protected]>
 
 	* TdsConnectionParameter.cs :

+ 19 - 10
mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds.cs

@@ -87,7 +87,7 @@ namespace Mono.Data.Tds.Protocol {
 		ArrayList outputParameters = new ArrayList ();
 		protected TdsInternalErrorCollection messages = new TdsInternalErrorCollection ();
 
-		int recordsAffected = 0;
+		int recordsAffected = -1;
 
 		#endregion // Fields
 
@@ -233,6 +233,11 @@ namespace Mono.Data.Tds.Protocol {
 			return true;
 		}
 
+		protected virtual bool IsValidRowCount (byte status, byte op)
+		{
+			return ((status & (0x10)) != 0) ;
+		}
+
 		public void Execute (string sql)
 		{
 			Execute (sql, null, 0, false);
@@ -1062,14 +1067,15 @@ namespace Mono.Data.Tds.Protocol {
 
 			int rowCount = comm.GetTdsInt ();
 
-			if (op == (byte) 0xc1) 
-				rowCount = 0;
-
-                        bool validRowCount = ( (status & 0x10) != 0);
+			bool validRowCount = IsValidRowCount (status,op);
 
 			if (type == TdsPacketSubType.DoneInProc) {
-                                if (validRowCount && rowCount > 0)
-                                        recordsAffected += rowCount;
+                                if (validRowCount) {
+					if (recordsAffected == -1)
+						recordsAffected = rowCount; 
+					else 
+						recordsAffected += rowCount;
+				}
                         }
                         
 
@@ -1082,9 +1088,12 @@ namespace Mono.Data.Tds.Protocol {
 					goto case TdsPacketSubType.Done;
 
 				case TdsPacketSubType.Done:
-					if (validRowCount && rowCount > 0)
-						recordsAffected += rowCount;
-
+					if (validRowCount) {
+						if (recordsAffected == -1) 
+							recordsAffected = rowCount;
+						else
+							recordsAffected += rowCount;
+					}
 					break;
 			}
 

+ 7 - 0
mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds70.cs

@@ -587,6 +587,13 @@ namespace Mono.Data.Tds.Protocol {
 			parms.Add (new TdsMetaParameter ("@P1", "int", Int32.Parse (statementId)));
 			ExecProc ("sp_unprepare", parms, 0, false);
 		}
+		
+		protected override bool IsValidRowCount (byte status, byte op)
+		{
+			if ((status & (byte)0x10) == 0 || op == (byte)0xc1)
+				return false;
+			return true; 
+		}
 
 		#endregion // Methods
 

+ 8 - 0
mcs/class/System.Data/System.Data.SqlClient/ChangeLog

@@ -1,3 +1,11 @@
+2005-10-27  Senganal T  <[email protected]>
+
+	* SqlCommand.cs 
+	* SqlDataReader.cs 
+	
+	Made changes so that the number of rows affected can be got directly from 
+	Tds regardsless of the type of query.Fixes bug #75698
+
 2005-10-19  Senganal T  <[email protected]>
 
 	* SqlConnection.cs (SetProperties) :

+ 5 - 29
mcs/class/System.Data/System.Data.SqlClient/SqlCommand.cs

@@ -320,7 +320,7 @@ namespace System.Data.SqlClient {
 
 		private void Execute (CommandBehavior behavior, bool wantResults)
 		{
-                        Connection.Tds.RecordsAffected = 0;
+                        Connection.Tds.RecordsAffected = -1;
 			TdsMetaParameterCollection parms = Parameters.MetaParameters;
 			if (preparedStatement == null) {
 				bool schemaOnly = ((behavior & CommandBehavior.SchemaOnly) > 0);
@@ -370,19 +370,7 @@ namespace System.Data.SqlClient {
 
 			try {
 				Execute (CommandBehavior.Default, false);
-				if (commandType == CommandType.StoredProcedure)
-					result = -1;
-				else {
-					// .NET documentation says that except for INSERT, UPDATE and
-					// DELETE  where the return value is the number of rows affected
-					// for the rest of the commands the return value is -1.	
-					if ((CommandText.ToUpper().IndexOf("UPDATE")!=-1) ||
-					    (CommandText.ToUpper().IndexOf("INSERT")!=-1) ||  	
-					    (CommandText.ToUpper().IndexOf("DELETE")!=-1))	
-						result = Connection.Tds.RecordsAffected;
-					else
-						result = -1;
-				      }		
+				result = Connection.Tds.RecordsAffected;
 			}
 			catch (TdsTimeoutException e) {
 				throw SqlException.FromTdsInternalException ((TdsInternalException) e);
@@ -595,7 +583,7 @@ namespace System.Data.SqlClient {
                                                             object state)
                 {
                         IAsyncResult ar = null;
-                        Connection.Tds.RecordsAffected = 0;
+                        Connection.Tds.RecordsAffected = -1;
 			TdsMetaParameterCollection parms = Parameters.MetaParameters;
 			if (preparedStatement == null) {
 				bool schemaOnly = ((behavior & CommandBehavior.SchemaOnly) > 0);
@@ -675,20 +663,8 @@ namespace System.Data.SqlClient {
                         ValidateAsyncResult (ar, "EndExecuteNonQuery");
                         EndExecuteInternal (ar);
                         
-                        int ret;
-                        if (commandType == CommandType.StoredProcedure)
-                                ret = -1;
-                        else {
-                                // .NET documentation says that except for INSERT, UPDATE and
-                                // DELETE  where the return value is the number of rows affected
-                                // for the rest of the commands the return value is -1.	
-                                if ((CommandText.ToUpper().IndexOf("UPDATE")!=-1) ||
-                                    (CommandText.ToUpper().IndexOf("INSERT")!=-1) ||  	
-                                    (CommandText.ToUpper().IndexOf("DELETE")!=-1))	
-                                        ret = Connection.Tds.RecordsAffected;
-                                else
-                                        ret = -1;
-                        }
+			int ret = Connection.Tds.RecordsAffected;
+
                         GetOutputParameters ();
                         ( (SqlAsyncResult) ar).Ended = true;
                         return ret;

+ 2 - 7
mcs/class/System.Data/System.Data.SqlClient/SqlDataReader.cs

@@ -59,7 +59,6 @@ namespace System.Data.SqlClient {
 		bool disposed = false;
 		int fieldCount;
 		bool isClosed;
-		bool isSelect;
 		bool moreResults;
 		int resultsRead;
 		int rowsRead;
@@ -86,8 +85,7 @@ namespace System.Data.SqlClient {
 			resultsRead = 0;
 			fieldCount = 0;
 			isClosed = false;
-			isSelect = (command.CommandText.Trim ().ToUpper ().StartsWith ("SELECT"));
-			command.Tds.RecordsAffected = 0;
+			command.Tds.RecordsAffected = -1;
 			NextResult ();
 		}
 
@@ -141,10 +139,7 @@ namespace System.Data.SqlClient {
 #endif // NET_2_0
                 int RecordsAffected {
 			get { 
-				if (isSelect) 
-					return -1;
-				else
-					return command.Tds.RecordsAffected; 
+				return command.Tds.RecordsAffected; 
 			}
 		}
 

+ 4 - 0
mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/ChangeLog

@@ -1,3 +1,7 @@
+2005-10-27  Senganal T  <[email protected]>
+
+	* SqlCommandTest.cs : Added Testcase for bug #75698
+
 2005-10-17  Senganal T  <[email protected]>
 
 	* SqlDataAdapterTest.cs : Added Testcase for bug #76433.

+ 8 - 1
mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/SqlCommandTest.cs

@@ -224,9 +224,16 @@ namespace MonoTests.System.Data.SqlClient
 				result = cmd.ExecuteNonQuery ();
 				Assert.AreEqual (1, result, "#3 One row shud be updated");
 
+				// Test Batch Commands 
+				cmd.CommandText = "Select id from numeric_family where id=1;";	
+				cmd.CommandText += "update numeric_family set type_int=10 where id=1000";
+				cmd.CommandText += "update numeric_family set type_int=10 where id=100";
+				result = cmd.ExecuteNonQuery ();	
+				Assert.AreEqual (1, result, "#4 One row shud be updated");
+				
 				cmd.CommandText = "Delete from numeric_family where id=100";
 				result = cmd.ExecuteNonQuery ();
-				Assert.AreEqual (1, result, "#4 One row shud be deleted");
+				Assert.AreEqual (1, result, "#5 One row shud be deleted");
 
 			}finally {
 				trans.Rollback ();