Browse Source

2007-05-30 Nagappan A <[email protected]>

	* SqlParameter.cs (SqlParameter): Updated constructor to use the
	new TDS RPC implementation.
	Fixed missing attributes.
	(SetDbType): Added new case for sql_variant type.
	(ConvertToFrameworkType): Implemented new private method to
	convert the data type to framework type.

	* SqlParameterCollection.cs: Fixed missing attributes and
	implemented missing methods.

	* SqlConnection.cs: Fixed missing attributes.

	* SqlConnectionStringBuilder.cs: Certain attributes are missing or
	its value or they are not appropriate. Fixed them.

	* SqlDataReader.cs (GetData): Method is available only under 1.0
	profile.
	
	* SqlCommandBuilder.cs: Certain attributes are available only
	under 2.0 profile, so moved them inside ifdef.

	* SqlCommand.cs: Certain attributes are available only under 2.0
	profile, so moved them inside ifdef.


svn path=/trunk/mcs/; revision=78186
Nagappan Alagappan 18 years ago
parent
commit
0fd75cc776

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

@@ -1,5 +1,29 @@
 2007-05-30  Nagappan A  <[email protected]>
 
+	* SqlParameter.cs (SqlParameter): Updated constructor to use the
+	new TDS RPC implementation.
+	Fixed missing attributes.
+	(SetDbType): Added new case for sql_variant type.
+	(ConvertToFrameworkType): Implemented new private method to
+	convert the data type to framework type.
+
+	* SqlParameterCollection.cs: Fixed missing attributes and
+	implemented missing methods.
+
+	* SqlConnection.cs: Fixed missing attributes.
+
+	* SqlConnectionStringBuilder.cs: Certain attributes are missing or
+	its value or they are not appropriate. Fixed them.
+
+	* SqlDataReader.cs (GetData): Method is available only under 1.0
+	profile.
+	
+	* SqlCommandBuilder.cs: Certain attributes are available only
+	under 2.0 profile, so moved them inside ifdef.
+
+	* SqlCommand.cs: Certain attributes are available only under 2.0
+	profile, so moved them inside ifdef.
+
 	* SqlBulkCopy.cs: Added new stubs.
 
 	* SqlBulkCopyColumnMappingCollection.cs: Added new stubs.

+ 7 - 1
mcs/class/System.Data/System.Data.SqlClient/SqlCommand.cs

@@ -53,8 +53,8 @@ using System.Xml;
 namespace System.Data.SqlClient {
 	[DesignerAttribute ("Microsoft.VSDesigner.Data.VS.SqlCommandDesigner, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.ComponentModel.Design.IDesigner")]
 	 [ToolboxItemAttribute ("System.Drawing.Design.ToolboxItem, "+ Consts.AssemblySystem_Drawing)]
-	[DefaultEventAttribute ("RecordsAffected")]
 #if NET_2_0
+	[DefaultEventAttribute ("RecordsAffected")]
 	public sealed class SqlCommand : DbCommand, IDbCommand, ICloneable
 #else
         public sealed class SqlCommand : Component, IDbCommand, ICloneable
@@ -224,7 +224,9 @@ namespace System.Data.SqlClient {
 		[Browsable (false)]
 		[DefaultValue (true)]
 		[DesignOnly (true)]
+#if NET_2_0
 		[EditorBrowsable (EditorBrowsableState.Never)]
+#endif
 		public 
 #if NET_2_0
                 override
@@ -307,6 +309,8 @@ namespace System.Data.SqlClient {
 		}
 
 #if NET_2_0
+		[Browsable (false)]
+		[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
 		public SqlNotificationRequest Notification { 
 			get { return notification; } 
 			set { notification = value; }
@@ -576,6 +580,7 @@ namespace System.Data.SqlClient {
 			return ExecuteReader (behavior);
 		}
 
+#if NET_2_0
 		protected override void Dispose (bool disposing)
 		{
 			if (disposed) return;
@@ -586,6 +591,7 @@ namespace System.Data.SqlClient {
 			}
 			disposed = true;
 		}
+#endif
 
 		public 
 #if NET_2_0

+ 9 - 7
mcs/class/System.Data/System.Data.SqlClient/SqlCommandBuilder.cs

@@ -118,11 +118,12 @@ namespace System.Data.SqlClient {
 		}
 
 		[Browsable (false)]
+		[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
 #if !NET_2_0
 		[DataSysDescription ("The character used in a text command as the opening quote for quoting identifiers that contain special characters.")]
-#endif
-		[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
+#else
 		[EditorBrowsable (EditorBrowsableState.Never)]
+#endif // NET_2_0
 		public 
 #if NET_2_0
 		override
@@ -137,11 +138,12 @@ namespace System.Data.SqlClient {
 		}
 
 		[Browsable (false)]
+		[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
 #if !NET_2_0
 		[DataSysDescription ("The character used in a text command as the closing quote for quoting identifiers that contain special characters. ")]
-#endif
-		[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
+#else
 		[EditorBrowsable (EditorBrowsableState.Never)]
+#endif // NET_2_0
 		public 
 #if NET_2_0
 		override
@@ -632,11 +634,11 @@ namespace System.Data.SqlClient {
 			return true;
 		}
 
-		public 
+		public
 #if NET_2_0
 		override
-#endif // NET_2_0
-                void RefreshSchema () 
+#endif
+		void RefreshSchema () 
 		{
 			// FIXME: "Figure out what else needs to be cleaned up when we refresh."
 			tableName = String.Empty;

+ 3 - 1
mcs/class/System.Data/System.Data.SqlClient/SqlConnection.cs

@@ -184,9 +184,10 @@ namespace System.Data.SqlClient {
 
 #if !NET_2_0
 		[DataSysDescription ("Current SqlServer that the connection is opened to, 'Data Source=X' in the connection string. ")]
+#else
+		[Browsable(true)]
 #endif
 		[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
-		[Browsable(true)]
 		public 
 #if NET_2_0
 		override
@@ -266,6 +267,7 @@ namespace System.Data.SqlClient {
 			set { fireInfoMessageEventOnUserErrors = value; }
 		}
 		
+		[DefaultValue (false)]
 		public bool StatisticsEnabled { 
 			get { return statisticsEnabled; } 
 			set { statisticsEnabled = value; }

+ 10 - 1
mcs/class/System.Data/System.Data.SqlClient/SqlConnectionStringBuilder.cs

@@ -187,6 +187,7 @@ namespace System.Data.SqlClient
 			}
 		}
 
+		[EditorBrowsable (EditorBrowsableState.Never)]
 		[DisplayNameAttribute ("AttachDbFilename")]
 		[RefreshPropertiesAttribute (RefreshProperties.All)]
 		public string AttachDBFilename { 
@@ -228,6 +229,7 @@ namespace System.Data.SqlClient
 		}
 
 		[DisplayNameAttribute ("Data Source")]
+		[TypeConverterAttribute (typeof (string))]
 		[RefreshPropertiesAttribute (RefreshProperties.All)]
 		public string DataSource { 
 			get { return _dataSource; }
@@ -258,6 +260,7 @@ namespace System.Data.SqlClient
 		}
 
 		[DisplayNameAttribute ("Failover Partner")]
+		[TypeConverterAttribute (typeof (string))]
 		[RefreshPropertiesAttribute (RefreshProperties.All)]
 		public string FailoverPartner { 
 			get { return _failoverPartner; }
@@ -268,6 +271,7 @@ namespace System.Data.SqlClient
 		}
 
 		[DisplayNameAttribute ("Initial Catalog")]
+		[TypeConverterAttribute (typeof (string))]
 		[RefreshPropertiesAttribute (RefreshProperties.All)]
 		public string InitialCatalog { 
 			get { return _initialCatalog; }
@@ -344,6 +348,7 @@ namespace System.Data.SqlClient
 		}
 
 		[DisplayNameAttribute ("Network Library")]
+		[TypeConverterAttribute (typeof (string))]
 		[RefreshPropertiesAttribute (RefreshProperties.All)]
 		public string NetworkLibrary { 
 			get { return _networkLibrary; }
@@ -428,7 +433,8 @@ namespace System.Data.SqlClient
 			}
 		}
 
-		[DisplayNameAttribute ("Trust Server Certificate")]
+		[DisplayNameAttribute ("TrustServerCertificate")]
+		[RefreshProperties (RefreshProperties.All)]
 		public bool TrustServerCertificate { 
 			get { return _trustServerCertificate; } 
 			set {
@@ -438,6 +444,7 @@ namespace System.Data.SqlClient
 		}
 
 		[DisplayNameAttribute ("Type System Version")]
+		[RefreshProperties (RefreshProperties.All)]
 		public string TypeSystemVersion { 
 			get { return _typeSystemVersion; } 
 			set {
@@ -447,6 +454,7 @@ namespace System.Data.SqlClient
 		}
 
 		[DisplayNameAttribute ("User Instance")]
+		[RefreshProperties (RefreshProperties.All)]
 		public bool UserInstance { 
 			get { return _userInstance; }
 			set { 
@@ -455,6 +463,7 @@ namespace System.Data.SqlClient
 			}
 		}
 
+		[RefreshPropertiesAttribute (RefreshProperties.All)]
 		[DisplayNameAttribute ("Context Connection")]
 		public bool ContextConnection { 
 			get { return _contextConnection; }

+ 0 - 1
mcs/class/System.Data/System.Data.SqlClient/SqlDataAdapter.cs

@@ -174,7 +174,6 @@ namespace System.Data.SqlClient {
 		}
 
 #if NET_2_0
-		[DefaultValue (1)]
 		public override int UpdateBatchSize { 
 			get { return updateBatchSize; }
 			set { 

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

@@ -376,11 +376,13 @@ namespace System.Data.SqlClient {
 			}
 		}
 		
+#if !NET_2_0
 		[EditorBrowsableAttribute (EditorBrowsableState.Never)] 
 		public new IDataReader GetData (int i)
 		{
 			return ((IDataReader) this [i]);
 		}
+#endif
 
 		public 
 #if NET_2_0
@@ -1085,7 +1087,7 @@ namespace System.Data.SqlClient {
 			GC.SuppressFinalize (this);
 		}
 
-		public 
+		public
 #if NET_2_0
 		override 
 #endif

+ 66 - 6
mcs/class/System.Data/System.Data.SqlClient/SqlParameter.cs

@@ -90,9 +90,10 @@ namespace System.Data.SqlClient {
 
 		public SqlParameter (string parameterName, object value) 
 		{
-			metaParameter = new TdsMetaParameter (parameterName, SqlTypeToFrameworkType (value));
+ 			metaParameter = new TdsMetaParameter (parameterName, value);
+ 			InferSqlType (value);
+ 			metaParameter.Value =  SqlTypeToFrameworkType(value);
 			this.sourceVersion = DataRowVersion.Current;
-			InferSqlType (value);
 		}
 		
 		public SqlParameter (string parameterName, SqlDbType dbType) 
@@ -116,8 +117,10 @@ namespace System.Data.SqlClient {
 			metaParameter = new TdsMetaParameter (parameterName, size, 
 							      isNullable, precision, 
 							      scale, 
-							      SqlTypeToFrameworkType (value));
-			SqlDbType = dbType;
+							      value);
+			if (dbType != SqlDbType.Variant) 
+				SqlDbType = dbType;
+			metaParameter.Value = SqlTypeToFrameworkType (value);
 			Direction = direction;
 			SourceColumn = sourceColumn;
 			SourceVersion = sourceVersion;
@@ -299,6 +302,7 @@ namespace System.Data.SqlClient {
 		[DefaultValue (0)]
 #if ONLY_1_0 || ONLY_1_1
 		[DataSysDescription ("For decimal, numeric, varnumeric DBTypes.")]
+#else
 		[Browsable (false)]
 		[EditorBrowsable (EditorBrowsableState.Never)]
 #endif
@@ -311,6 +315,7 @@ namespace System.Data.SqlClient {
 		[DefaultValue (0)]
 #if ONLY_1_0 || ONLY_1_1
 		[DataSysDescription ("For decimal, numeric, varnumeric DBTypes.")]
+#else
 		[Browsable (false)]
                 [EditorBrowsable (EditorBrowsableState.Never)]
 #endif
@@ -407,11 +412,14 @@ namespace System.Data.SqlClient {
 			set{ compareInfo = value; }
 		}
 
+		[Browsable (false)]
 		public int LocaleId { 
 			get { return localeId; }
 			set { localeId = value; }
 		}
 
+		[Browsable (false)]
+		[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
 		public Object SqlValue { 
 			get { return sqlValue; }
 			set { sqlValue = value; }
@@ -460,7 +468,6 @@ namespace System.Data.SqlClient {
 			}
 
 			Type type = value.GetType ();
-
 			string exception = String.Format ("The parameter data type of {0} is invalid.", type.Name);
 
 			switch (type.FullName) {
@@ -690,6 +697,9 @@ namespace System.Data.SqlClient {
 			case "varchar":
 				SqlDbType = SqlDbType.VarChar;
 				break;
+			case "sql_variant":
+				SqlDbType = SqlDbType.Variant;
+				break;
 			default:
 				SqlDbType = SqlDbType.Variant;
 				break;
@@ -823,7 +833,7 @@ namespace System.Data.SqlClient {
 		private object SqlTypeToFrameworkType (object value)
 		{
 			if (! (value is INullable)) // if the value is not SqlType
-				return value;
+				return ConvertToFrameworkType (value);
 
 			// Map to .net type, as Mono TDS respects only types from .net
 			switch (value.GetType ().FullName) {
@@ -857,6 +867,56 @@ namespace System.Data.SqlClient {
 			return value;
 		}
 
+		private object ConvertToFrameworkType (object value)
+		{
+			if (value == null || value == DBNull.Value)
+				return value;
+			switch (sqlDbType)  {
+			case SqlDbType.BigInt :
+				return Convert.ChangeType (value, typeof (Int64));
+			case SqlDbType.Binary:
+			case SqlDbType.VarBinary:
+				if (value is byte[])
+					return value;
+				break;
+			case SqlDbType.Bit:
+				return Convert.ChangeType (value, typeof (bool));
+			case SqlDbType.Int:
+				return Convert.ChangeType (value, typeof (Int32));
+			case SqlDbType.SmallInt :
+				return Convert.ChangeType (value, typeof (Int16));
+			case SqlDbType.TinyInt :
+				return Convert.ChangeType (value, typeof (byte));
+			case SqlDbType.Float:
+				return Convert.ChangeType (value, typeof (Double));
+			case SqlDbType.Real:
+				return Convert.ChangeType (value, typeof (Single));
+			case SqlDbType.Decimal:
+				return Convert.ChangeType (value, typeof (Decimal));
+			case SqlDbType.Money:
+			case SqlDbType.SmallMoney:
+				{
+					Decimal val = (Decimal)Convert.ChangeType (value, typeof (Decimal));
+					return Decimal.Round(val, 4);
+				}
+			case SqlDbType.DateTime:
+			case SqlDbType.SmallDateTime:
+				return Convert.ChangeType (value, typeof (DateTime));
+			case SqlDbType.VarChar:
+			case SqlDbType.NVarChar:
+			case SqlDbType.Char:
+			case SqlDbType.NChar:
+			case SqlDbType.Text:
+			case SqlDbType.NText:
+				return Convert.ChangeType (value,  typeof (string));
+			case SqlDbType.UniqueIdentifier:
+				return Convert.ChangeType (value,  typeof (Guid));
+			case SqlDbType.Variant:
+				return metaParameter.Value;
+			}
+			throw new  NotImplementedException ("Type Not Supported : " + sqlDbType.ToString());
+		}
+
 #if NET_2_0
 		
                 public override void ResetDbType ()

+ 8 - 4
mcs/class/System.Data/System.Data.SqlClient/SqlParameterCollection.cs

@@ -156,21 +156,21 @@ namespace System.Data.SqlClient {
 #if NET_2_0
 		protected  override DbParameter GetParameter (int index)
 		{
-			throw new NotImplementedException();
+			return this [index];
 		}
 
 		protected override DbParameter GetParameter (string parameterName)
 		{
-			throw new NotImplementedException ();
+			return this [parameterName];
 		}
 	
 		protected  override void SetParameter (int index, DbParameter value)
 		{
-                        throw new NotImplementedException();
+			this [index] = value;
                 }
 		protected override void SetParameter (string parameterName, DbParameter value)
 		{
-                        throw new NotImplementedException();
+			this [parameterName] = value;
                 }
 #endif
 		object IList.this [int index] {
@@ -204,7 +204,9 @@ namespace System.Data.SqlClient {
 
 		#region Methods
 
+#if NET_2_0
 		[EditorBrowsable (EditorBrowsableState.Never)]
+#endif // NET_2_0
 		public  
 #if NET_2_0
 		override
@@ -228,8 +230,10 @@ namespace System.Data.SqlClient {
 			return value;
 		}
 		
+#if NET_2_0
 		[EditorBrowsable (EditorBrowsableState.Never)]
 		[Obsolete ("Do not call this method.")]
+#endif // NET_2_0
 		public SqlParameter Add (string parameterName, object value)
 		{
 			return Add (new SqlParameter (parameterName, value));