Преглед изворни кода

* OdbcError.cs: fixed serialization compatibility with MS.NET
* OdbcErrorCollection.cs: fixed serialization compatibility with
MS.NET
* OdbcException.cs: fixed serialization compatibility with MS.NET

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

Gert Driesen пре 21 година
родитељ
комит
8c65905adb

+ 7 - 0
mcs/class/System.Data/System.Data.Odbc/ChangeLog

@@ -1,3 +1,10 @@
+2004-06-16  Gert Driesen <[email protected]>
+
+	* OdbcError.cs: fixed serialization compatibility with MS.NET
+	* OdbcErrorCollection.cs: fixed serialization compatibility with
+	MS.NET
+	* OdbcException.cs: fixed serialization compatibility with MS.NET
+
 2004-06-16  Sureshkumar T ([email protected])
 	* OdbcDataReader.cs: Added GetValue support for Sql Binary type to return byte array.
 			     Implemented GetBytes method.

+ 131 - 128
mcs/class/System.Data/System.Data.Odbc/OdbcError.cs

@@ -1,11 +1,11 @@
-//
-// System.Data.Odbc.OdbcError
-//
-// Author:
-//   Brian Ritchie ([email protected]) 
-//
-// Copyright (C) Brian Ritchie, 2002
-//
+//
+// System.Data.Odbc.OdbcError
+//
+// Author:
+//   Brian Ritchie ([email protected]) 
+//
+// Copyright (C) Brian Ritchie, 2002
+//
 
 //
 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
@@ -29,123 +29,126 @@
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
-
-using System.Collections;
-using System.ComponentModel;
-using System.Data;
-using System.Data.Common;
-
-namespace System.Data.Odbc
-{
-	public sealed class OdbcError
-	{
-		string message,source,sqlstate;
-		int nativeerror;
-
-		#region Constructors
-
-		internal OdbcError(string Source)
-		{
-			nativeerror=1;
-			source=Source;
-			message="Error in "+source;
-			sqlstate="";
-		}
-
-		internal OdbcError(string Source, OdbcHandleType HandleType, IntPtr Handle)
-		{
-			short buflen=256,txtlen=0;
-			OdbcReturn ret=OdbcReturn.Success;
-			byte[] buf_MsgText=new byte[buflen];
-			byte[] buf_SqlState=new byte[buflen];
-			bool NeedsDecode=true;
-			this.source=Source;
-			switch (HandleType)
-			{
-				case OdbcHandleType.Dbc:
-					ret=libodbc.SQLError(IntPtr.Zero,Handle,IntPtr.Zero, buf_SqlState,
-						ref nativeerror, buf_MsgText, buflen, ref txtlen);
-					break;
-				case OdbcHandleType.Stmt:
-					ret=libodbc.SQLError(IntPtr.Zero,IntPtr.Zero,Handle, buf_SqlState,
-						ref nativeerror, buf_MsgText, buflen, ref txtlen);
-					break;
-				case OdbcHandleType.Env:
-					ret=libodbc.SQLError(Handle,IntPtr.Zero,IntPtr.Zero, buf_SqlState,
-						ref nativeerror, buf_MsgText, buflen, ref txtlen);
-					break;
-				default:
-					nativeerror=1;
-					source=Source;
-					message="Error in "+source;
-					sqlstate="";
-					NeedsDecode=false;
-					break;
-			}
-			if (NeedsDecode)
-			{
-				if (ret!=OdbcReturn.Success)
-				{
-					nativeerror=1;
-					source=Source;
-					message="Unable to retreive error information from ODBC driver manager";
-					sqlstate="";
-				}
-				else
-				{
-					sqlstate=System.Text.Encoding.Default.GetString(buf_SqlState).Replace((char) 0,' ').Trim();;
-					message=System.Text.Encoding.Default.GetString(buf_MsgText).Replace((char) 0,' ').Trim();;
-				}
-			}
-		}
-
-		#endregion // Constructors
-		
-		#region Properties
-
-		public string Message
-		{
-			get
-			{
-				return message;
-			}
-		}
-
-		public int NativeError
-		{
-			get
-			{
-				return nativeerror;
-			}
-		}
-
-		public string Source
-		{
-			get
-			{
-				return source;
-			}
-		}
-
-		public string SQLState
-		{
-			get
-			{
-				return sqlstate;
-			}
-		}
-
-		#endregion // Properties
-		
-		#region methods
-		
-		public override string ToString () 
-		{
-			return Message;
-		}	
-			
-		#endregion
-
-	}
-
-}
+
+using System.Collections;
+using System.ComponentModel;
+using System.Data;
+using System.Data.Common;
+
+namespace System.Data.Odbc
+{
+	[Serializable]
+	public sealed class OdbcError
+	{
+		string _message;
+		string _source;
+		string _state;
+		int _nativeerror;
+
+		#region Constructors
+
+		internal OdbcError(string Source)
+		{
+			_nativeerror = 1;
+			_source = Source;
+			_message = "Error in " + _source;
+			_state = "";
+		}
+
+		internal OdbcError(string Source, OdbcHandleType HandleType, IntPtr Handle)
+		{
+			short buflen=256,txtlen=0;
+			OdbcReturn ret=OdbcReturn.Success;
+			byte[] buf_MsgText=new byte[buflen];
+			byte[] buf_SqlState=new byte[buflen];
+			bool NeedsDecode=true;
+			_source = Source;
+			switch (HandleType)
+			{
+				case OdbcHandleType.Dbc:
+					ret=libodbc.SQLError(IntPtr.Zero,Handle,IntPtr.Zero, buf_SqlState,
+						ref _nativeerror, buf_MsgText, buflen, ref txtlen);
+					break;
+				case OdbcHandleType.Stmt:
+					ret=libodbc.SQLError(IntPtr.Zero,IntPtr.Zero,Handle, buf_SqlState,
+						ref _nativeerror, buf_MsgText, buflen, ref txtlen);
+					break;
+				case OdbcHandleType.Env:
+					ret=libodbc.SQLError(Handle,IntPtr.Zero,IntPtr.Zero, buf_SqlState,
+						ref _nativeerror, buf_MsgText, buflen, ref txtlen);
+					break;
+				default:
+					_nativeerror = 1;
+					_source = Source;
+					_message = "Error in " + _source;
+					_state = "";
+					NeedsDecode=false;
+					break;
+			}
+			if (NeedsDecode)
+			{
+				if (ret!=OdbcReturn.Success)
+				{
+					_nativeerror = 1;
+					_source = Source;
+					_message = "Unable to retreive error information from ODBC driver manager";
+					_state = "";
+				}
+				else
+				{
+					_state = System.Text.Encoding.Default.GetString (buf_SqlState).Replace ((char) 0, ' ').Trim ();
+					_message = System.Text.Encoding.Default.GetString (buf_MsgText).Replace ((char) 0, ' ').Trim ();
+				}
+			}
+		}
+
+		#endregion // Constructors
+		
+		#region Properties
+
+		public string Message
+		{
+			get
+			{
+				return _message;
+			}
+		}
+
+		public int NativeError
+		{
+			get
+			{
+				return _nativeerror;
+			}
+		}
+
+		public string Source
+		{
+			get
+			{
+				return _source;
+			}
+		}
+
+		public string SQLState
+		{
+			get
+			{
+				return _state;
+			}
+		}
+
+		#endregion // Properties
+		
+		#region methods
+		
+		public override string ToString () 
+		{
+			return Message;
+		}	
+			
+		#endregion
+
+	}
+
+}

+ 104 - 103
mcs/class/System.Data/System.Data.Odbc/OdbcErrorCollection.cs

@@ -1,11 +1,11 @@
-//
-// System.Data.Odbc.OdbcErrorCollection
-//
-// Author:
-//   Brian Ritchie ([email protected]) 
-//
-// Copyright (C) Brian Ritchie, 2002
-//
+//
+// System.Data.Odbc.OdbcErrorCollection
+//
+// Author:
+//   Brian Ritchie ([email protected]) 
+//
+// Copyright (C) Brian Ritchie, 2002
+//
 
 //
 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
@@ -29,98 +29,99 @@
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
-
-using System.Collections;
-using System.ComponentModel;
-using System.Data;
-using System.Data.Common;
-
-namespace System.Data.Odbc
-{
-	public sealed class OdbcErrorCollection : ICollection, IEnumerable
-	{
-		#region Fields
-
-		ArrayList list = new ArrayList ();
-	
-		#endregion // Fields
-
-		#region Constructors
-
-		internal OdbcErrorCollection() {
-		}
-
-		#endregion Constructors
-
-		#region Properties 
-
-		public int Count 
-		{
-			get 
-			{
-				return list.Count;
-			}
-		}
-
-		public OdbcError this[int index] 
-		{
-			get 
-			{
-				return (OdbcError) list[index];
-			}
-		}
-
-		object ICollection.SyncRoot 
-		{
-			get 
-			{
-				return list.SyncRoot;
-			}
-		}
-
-		bool ICollection.IsSynchronized 
-		{
-			get 
-			{
-				return list.IsSynchronized;
-			}
-		}
-
-		#endregion // Properties
-
-		#region Methods
-
-		internal void Add (OdbcError error)
-		{
-			list.Add ((object) error);
-		}
-		
-		public void CopyTo (Array array, int index)
-		{
-			if (array == null)
-				throw new ArgumentNullException("array");		
-			
-			if ((index < array.GetLowerBound (0)) || (index > array.GetUpperBound (0)))
-				throw new ArgumentOutOfRangeException("index");
-		
-			// is the check for IsFixedSize required?
-			if ((array.IsFixedSize) || (index + this.Count > array.GetUpperBound (0)))
-				throw new ArgumentException("array");
-
-			((OdbcError[])(list.ToArray ())).CopyTo (array, index);
-			 
-		}
-
-		public IEnumerator GetEnumerator ()
-		{
-			return list.GetEnumerator ();
-		}
-
-		IEnumerator IEnumerable.GetEnumerator ()
-		{
-			return GetEnumerator ();
-		}
-
-		#endregion // Methods
-	}
-}
+
+using System.Collections;
+using System.ComponentModel;
+using System.Data;
+using System.Data.Common;
+
+namespace System.Data.Odbc
+{
+	[Serializable]
+	public sealed class OdbcErrorCollection : ICollection, IEnumerable
+	{
+		#region Fields
+
+		ArrayList _items = new ArrayList ();
+	
+		#endregion // Fields
+
+		#region Constructors
+
+		internal OdbcErrorCollection() {
+		}
+
+		#endregion Constructors
+
+		#region Properties 
+
+		public int Count 
+		{
+			get 
+			{
+				return _items.Count;
+			}
+		}
+
+		public OdbcError this[int index] 
+		{
+			get 
+			{
+				return (OdbcError) _items[index];
+			}
+		}
+
+		object ICollection.SyncRoot 
+		{
+			get 
+			{
+				return _items.SyncRoot;
+			}
+		}
+
+		bool ICollection.IsSynchronized 
+		{
+			get 
+			{
+				return _items.IsSynchronized;
+			}
+		}
+
+		#endregion // Properties
+
+		#region Methods
+
+		internal void Add (OdbcError error)
+		{
+			_items.Add ((object) error);
+		}
+		
+		public void CopyTo (Array array, int index)
+		{
+			if (array == null)
+				throw new ArgumentNullException("array");		
+			
+			if ((index < array.GetLowerBound (0)) || (index > array.GetUpperBound (0)))
+				throw new ArgumentOutOfRangeException("index");
+		
+			// is the check for IsFixedSize required?
+			if ((array.IsFixedSize) || (index + this.Count > array.GetUpperBound (0)))
+				throw new ArgumentException("array");
+
+			((OdbcError[]) (_items.ToArray ())).CopyTo (array, index);
+
+		}
+
+		public IEnumerator GetEnumerator ()
+		{
+			return _items.GetEnumerator ();
+		}
+
+		IEnumerator IEnumerable.GetEnumerator ()
+		{
+			return GetEnumerator ();
+		}
+
+		#endregion // Methods
+	}
+}

+ 74 - 67
mcs/class/System.Data/System.Data.Odbc/OdbcException.cs

@@ -1,11 +1,11 @@
-//
-// System.Data.Odbc.OdbcDataReader
-//
-// Author:
-//   Brian Ritchie ([email protected]) 
-//
-// Copyright (C) Brian Ritchie, 2002
-//
+//
+// System.Data.Odbc.OdbcException
+//
+// Author:
+//   Brian Ritchie ([email protected])
+//
+// Copyright (C) Brian Ritchie, 2002
+//
 
 //
 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
@@ -29,62 +29,69 @@
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
-
-using System.Collections;
-using System.ComponentModel;
-using System.Data;
-using System.Data.Common;
-using System.Runtime.InteropServices;
-using System.Runtime.Serialization;
-
-namespace System.Data.Odbc
-{
-	public sealed class OdbcException : SystemException 
-	{
-		OdbcErrorCollection col;
-
-		internal OdbcException(OdbcError Error) : base (Error.Message)
-		{
-			col=new OdbcErrorCollection();
-			col.Add(Error);
-		}
-
-		public OdbcErrorCollection Errors 
-		{
-			get 
-			{
-				return col;
-			}
-		}
-
-		public override string Source 
-		{	
-			get
-			{
-				return col[0].Source;
-			}
-		}
-
-
-		public override string Message {
-			get 
-			{
-				
-				return  col[0].Message;
-			}
-		}	
-		
-		#region Methods
-
-		public override void GetObjectData (SerializationInfo si, StreamingContext context)
-		{
-			if (si == null)
-				throw new ArgumentNullException ("si");
-
-			si.AddValue ("col", col);
-			base.GetObjectData (si, context);
-		}
-
-		#endregion // Methods
-	}
-}
+
+using System.Collections;
+using System.ComponentModel;
+using System.Data;
+using System.Data.Common;
+using System.Runtime.InteropServices;
+using System.Runtime.Serialization;
+
+namespace System.Data.Odbc
+{
+	[Serializable]
+	public sealed class OdbcException : SystemException
+	{
+		OdbcErrorCollection odbcErrors;
+
+		internal OdbcException(OdbcError Error) : base (Error.Message)
+		{
+			odbcErrors = new OdbcErrorCollection ();
+			odbcErrors.Add (Error);
+		}
+
+		public OdbcErrorCollection Errors 
+		{
+			get 
+			{
+				return odbcErrors;
+			}
+		}
+
+		public override string Source 
+		{	
+			get
+			{
+				return odbcErrors[0].Source;
+			}
+		}
+
+
+		public override string Message {
+			get 
+			{
+
+				return odbcErrors[0].Message;
+			}
+		}
+
+		private OdbcException (SerializationInfo si, StreamingContext sc) : base(si, sc)
+		{
+			odbcErrors = new OdbcErrorCollection ();
+			odbcErrors = ((OdbcErrorCollection) si.GetValue ("odbcErrors", typeof(OdbcErrorCollection)));
+		}
+
+		#region Methods
+
+		public override void GetObjectData (SerializationInfo si, StreamingContext context)
+		{
+			if (si == null)
+				throw new ArgumentNullException ("si");
+
+			si.AddValue ("odbcErrors", odbcErrors, typeof(OdbcErrorCollection));
+			base.GetObjectData (si, context);
+		}
+
+		#endregion // Methods
+	}
+}