Просмотр исходного кода

2002-12-10 Gonzalo Paniagua Javier <[email protected]>

	* Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds.cs:
	(Disconnect): close the stream and set connected to false.
	(NextResult): check if after DoneProc we have a ColumnMetadata + Row,
	which holds the values for the output parameters and read them.
	(LoadRow): add the values to outputParameters if DoneProc.
	When executing a stored procedure, we execute the procedure and then
	select the parameter values.

	* Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds70.cs:
	(BuildParameters): check Parameters.

	* Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsComm.cs: added Close () to
	close the stream.

	* Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsConnectionParameters.cs:
	initialize all the string to be empty.

	* System.Data/System.Data.SqlClient/SqlCommand.cs:
	(CloseReader): don't get the output parameters here.
	(GetOutputParameters): don't skip the stream. The parameters will be
	there.

	* System.Data/System.Data.SqlClient/SqlConnection.cs: don't try to
	execute 'sp_reset_connection'.

	* System.Data/System.Data.SqlClient/SqlDataReader.cs: get the output
	parameters after the end of the results.

svn path=/trunk/mcs/; revision=9534
Gonzalo Paniagua Javier 23 лет назад
Родитель
Сommit
8d29a839ff

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

@@ -1,3 +1,20 @@
+2002-12-10  Gonzalo Paniagua Javier <[email protected]>
+
+	* Tds.cs:
+	(Disconnect): close the stream and set connected to false.
+	(NextResult): check if after DoneProc we have a ColumnMetadata + Row,
+	which holds the values for the output parameters and read them.
+	(LoadRow): add the values to outputParameters if DoneProc.
+	When executing a stored procedure, we execute the procedure and then
+	select the parameter values.
+
+	* Tds70.cs:
+	(BuildParameters): check Parameters.
+
+	* TdsComm.cs: added Close () to close the stream.
+
+	* TdsConnectionParameters.cs: initialize all the string to be empty.
+
 2002-11-04  Tim Coleman ([email protected])
 	* TdsBigDecimal.cs:
 		New class added to handle (potentially) large

+ 18 - 3
mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds.cs

@@ -184,8 +184,8 @@ namespace Mono.Data.Tds.Protocol {
 			comm.StartPacket (TdsPacketType.Logoff);
 			comm.Append ((byte) 0);
 			comm.SendPacket ();	
-
-			SkipToEnd ();
+			comm.Close ();
+			connected = false;
 		}
 
 		public void Execute (string sql)
@@ -237,14 +237,26 @@ namespace Mono.Data.Tds.Protocol {
 			TdsPacketSubType subType;
 
 			bool done = false;
+			bool outputParams = false;
 
 			while (!done) {
 				subType = ProcessSubPacket ();
+				if (outputParams) {
+					moreResults = false;
+					break;
+				}
+
 				switch (subType) {
 				case TdsPacketSubType.ColumnInfo:
 				case TdsPacketSubType.ColumnMetadata: 
 				case TdsPacketSubType.RowFormat: 
-					done = (Comm.Peek () != (byte) TdsPacketSubType.TableName);
+					byte peek = Comm.Peek ();
+					done = (peek != (byte) TdsPacketSubType.TableName);
+					if (done && doneProc && peek == (byte) TdsPacketSubType.Row) {
+						outputParams = true;
+						done = false;
+					}
+
 					break;
 				case TdsPacketSubType.TableName:
 					done = true;
@@ -763,6 +775,9 @@ namespace Mono.Data.Tds.Protocol {
 			foreach (TdsDataColumn column in columns) {
 				object o = GetColumnValue ((TdsColumnType) column["ColumnType"], false, i);
 				currentRow.Add (o);
+				if (doneProc)
+					outputParameters.Add (o);
+
 				if (o is TdsBigDecimal && currentRow.BigDecimalIndex < 0) 
 					currentRow.BigDecimalIndex = i;
 				i += 1;

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

@@ -45,6 +45,9 @@ namespace Mono.Data.Tds.Protocol {
 
 		private string BuildParameters ()
 		{
+			if (Parameters == null || parameters.Count == 0)
+				return String.Empty;
+
 			StringBuilder result = new StringBuilder ();
 			foreach (TdsMetaParameter p in Parameters) {
 				if (result.Length > 0)

+ 5 - 0
mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsComm.cs

@@ -215,6 +215,11 @@ namespace Mono.Data.Tds.Protocol {
 				Append (BitConverter.GetBytes (l));
 		}
 
+		public void Close ()
+		{
+			stream.Close ();
+		}
+
 		private void ConnectCallback (IAsyncResult ar)
 		{
 			Socket s = (Socket) ar.AsyncState;

+ 6 - 5
mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsConnectionParameters.cs

@@ -7,17 +7,18 @@
 // Copyright (C) 2002 Tim Coleman
 //
 
+using System;
 namespace Mono.Data.Tds.Protocol {
 	public class TdsConnectionParameters
 	{
 		public string ApplicationName = "Mono";
-		public string Database;
-		public string Charset;
+		public string Database = String.Empty;
+		public string Charset = String.Empty;
 		public string Hostname = "localhost";
-		public string Language;
+		public string Language = String.Empty;
 		public string LibraryName = "Mono";
-		public string Password;
+		public string Password = String.Empty;
 		public string ProgName = "Mono";
-		public string User;
+		public string User = String.Empty;
 	}
 }

+ 13 - 0
mcs/class/System.Data/ChangeLog

@@ -1,3 +1,16 @@
+2002-12-10  Gonzalo Paniagua Javier <[email protected]>
+
+	* System.Data.SqlClient/SqlCommand.cs:
+	(CloseReader): don't get the output parameters here.
+	(GetOutputParameters): don't skip the stream. The parameters will be
+	there.
+
+	* System.Data.SqlClient/SqlConnection.cs: don't try to execute
+	'sp_reset_connection'.
+
+	* System.Data.SqlClient/SqlDataReader.cs: get the output parameters
+	after the end of the results.
+
 2002-12-04  Ville Palo <[email protected]>
 
 	* System.Xml/XmlDataDocument.cs: Now this works in both ways,

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

@@ -202,7 +202,6 @@ namespace System.Data.SqlClient {
 
 		internal void CloseDataReader (bool moreResults)
 		{
-			GetOutputParameters ();
 			Connection.DataReader = null;
 
 			if ((behavior & CommandBehavior.CloseConnection) != 0)
@@ -345,11 +344,9 @@ namespace System.Data.SqlClient {
 			return xmlReader;
 		}
 
-		private void GetOutputParameters ()
+		internal void GetOutputParameters ()
 		{
-			Connection.Tds.SkipToEnd ();
-
-			IList list = Connection.Tds.ColumnValues;
+			IList list = Connection.Tds.OutputParameters;
 
 			if (list != null && list.Count > 0) {
 				int index = 0;

+ 5 - 0
mcs/class/System.Data/System.Data.SqlClient/SqlConnection.cs

@@ -351,8 +351,13 @@ namespace System.Data.SqlClient {
 
 			if (!tds.IsConnected) 
 				tds.Connect (parms);
+			/* Not sure ebout removing these 2 lines.
+			 * The command that gets to the sql server is just
+			 * 'sp_reset_connection' and it fails.
+			 * Either remove them definitely or fix it
 			else if (connectionReset)
 				tds.ExecProc ("sp_reset_connection");
+			*/
 				
 			ChangeState (ConnectionState.Open);
 		}

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

@@ -732,12 +732,13 @@ namespace System.Data.SqlClient {
 		{
 			if ((command.CommandBehavior & CommandBehavior.SingleResult) != 0 && resultsRead > 0)
 				return false;
-			if (command.Tds.DoneProc)
-				return false;
 
 			schemaTable.Rows.Clear ();
 
 			moreResults = command.Tds.NextResult ();
+			if (!moreResults)
+				command.GetOutputParameters ();
+
 			GetSchemaTable ();
 
 			rowsRead = 0;