List:Commits« Previous MessageNext Message »
From:rburnett Date:August 15 2008 8:16pm
Subject:Connector/NET commit: r1381 - in trunk/MySql.Data/Provider/Source: . Types common
View as plain text  
Modified:
   trunk/MySql.Data/Provider/Source/CommandBuilder.cs
   trunk/MySql.Data/Provider/Source/Driver.cs
   trunk/MySql.Data/Provider/Source/MySqlClientFactory.cs
   trunk/MySql.Data/Provider/Source/MySqlConnectionStringBuilder.cs
   trunk/MySql.Data/Provider/Source/MySqlPool.cs
   trunk/MySql.Data/Provider/Source/MySqlPoolManager.cs
   trunk/MySql.Data/Provider/Source/Statement.cs
   trunk/MySql.Data/Provider/Source/StoredProcedure.cs
   trunk/MySql.Data/Provider/Source/Types/MySqlDateTime.cs
   trunk/MySql.Data/Provider/Source/command.cs
   trunk/MySql.Data/Provider/Source/common/NativeMethods.cs
   trunk/MySql.Data/Provider/Source/datareader.cs
   trunk/MySql.Data/Provider/Source/parameter.cs
   trunk/MySql.Data/Provider/Source/parameter_collection.cs
Log:
pass 2 of FxCop cleanups

Modified: trunk/MySql.Data/Provider/Source/CommandBuilder.cs
===================================================================
--- trunk/MySql.Data/Provider/Source/CommandBuilder.cs	2008-08-15 16:45:56 UTC (rev 1380)
+++ trunk/MySql.Data/Provider/Source/CommandBuilder.cs	2008-08-15 18:16:56 UTC (rev 1381)
@@ -261,10 +261,11 @@
 
         protected override void SetRowUpdatingHandler(DbDataAdapter adapter)
         {
+            MySqlDataAdapter myAdapter = (adapter as MySqlDataAdapter);
             if (adapter != base.DataAdapter)
-                ((MySqlDataAdapter)adapter).RowUpdating += new
MySqlRowUpdatingEventHandler(RowUpdating);
+                myAdapter.RowUpdating += new MySqlRowUpdatingEventHandler(RowUpdating);
             else
-                ((MySqlDataAdapter)adapter).RowUpdating -= new
MySqlRowUpdatingEventHandler(RowUpdating);
+                myAdapter.RowUpdating -= new MySqlRowUpdatingEventHandler(RowUpdating);
         }
 
         private void RowUpdating(object sender, MySqlRowUpdatingEventArgs args)

Modified: trunk/MySql.Data/Provider/Source/Driver.cs
===================================================================
--- trunk/MySql.Data/Provider/Source/Driver.cs	2008-08-15 16:45:56 UTC (rev 1380)
+++ trunk/MySql.Data/Provider/Source/Driver.cs	2008-08-15 18:16:56 UTC (rev 1381)
@@ -59,8 +59,6 @@
             connectionString = settings;
             threadId = -1;
             serverCharSetIndex = -1;
-            serverCharSet = null;
-            hasWarnings = false;
         }
 
         #region Properties

Modified: trunk/MySql.Data/Provider/Source/MySqlClientFactory.cs
===================================================================
--- trunk/MySql.Data/Provider/Source/MySqlClientFactory.cs	2008-08-15 16:45:56 UTC (rev
1380)
+++ trunk/MySql.Data/Provider/Source/MySqlClientFactory.cs	2008-08-15 18:16:56 UTC (rev
1381)
@@ -35,15 +35,10 @@
         /// Gets an instance of the <see cref="MySqlClientFactory"/>. 
         /// This can be used to retrieve strongly typed data objects. 
         /// </summary>
-        public static readonly MySqlClientFactory Instance;
+        public static MySqlClientFactory Instance = new MySqlClientFactory();
         private Type dbServicesType;
         private FieldInfo mySqlDbProviderServicesInstance;
 
-        static MySqlClientFactory()
-        {
-            Instance = new MySqlClientFactory();
-        }
-
         /// <summary>
         /// Returns a strongly typed <see cref="DbCommandBuilder"/> instance. 
         /// </summary>

Modified: trunk/MySql.Data/Provider/Source/MySqlConnectionStringBuilder.cs
===================================================================
--- trunk/MySql.Data/Provider/Source/MySqlConnectionStringBuilder.cs	2008-08-15 16:45:56
UTC (rev 1380)
+++ trunk/MySql.Data/Provider/Source/MySqlConnectionStringBuilder.cs	2008-08-15 18:16:56
UTC (rev 1381)
@@ -931,17 +931,17 @@
 
         private static bool ConvertToBool(object value)
         {
-            if (value is string)
+            string valAsString = value as string;
+            if (valAsString != null)
             {
-                string s = value.ToString().ToUpper(CultureInfo.InvariantCulture);
+                string s = valAsString.ToUpper(CultureInfo.InvariantCulture);
                 if (s == "YES" || s == "TRUE") return true;
                 if (s == "NO" || s == "FALSE") return false;
-                throw new ArgumentException(Resources.ImproperValueFormat, (string)
value);
+                throw new ArgumentException(Resources.ImproperValueFormat, valAsString);
             }
             try
             {
-                return (value as IConvertible).ToBoolean(
-                    CultureInfo.InvariantCulture);
+                return (value as IConvertible).ToBoolean(CultureInfo.InvariantCulture);
             }
             catch (InvalidCastException)
             {
@@ -953,22 +953,24 @@
         {
             try
             {
-                if (value is MySqlConnectionProtocol) return (MySqlConnectionProtocol)
value;
+                if (value is MySqlConnectionProtocol) 
+                    return (MySqlConnectionProtocol) value;
                 return (MySqlConnectionProtocol) Enum.Parse(
                                                      typeof (MySqlConnectionProtocol),
value.ToString(), true);
             }
             catch (Exception)
             {
-                if (value is string)
+                string valAsString = value as String;
+                if (valAsString != null)
                 {
-                    string lowerString = (value as string).ToLower();
-                    if (lowerString == "socket" || lowerString == "tcp")
+                    string upperString =
valAsString.ToUpper(CultureInfo.InvariantCulture);
+                    if (upperString == "SOCKET" || upperString == "TCP")
                         return MySqlConnectionProtocol.Sockets;
-                    if (lowerString == "pipe")
+                    if (upperString == "PIPE")
                         return MySqlConnectionProtocol.NamedPipe;
-                    if (lowerString == "unix")
+                    if (upperString == "UNIX")
                         return MySqlConnectionProtocol.UnixSocket;
-                    if (lowerString == "memory")
+                    if (upperString == "MEMORY")
                         return MySqlConnectionProtocol.SharedMemory;
                 }
             }
@@ -1265,24 +1267,25 @@
 
         private void SetValue(Keyword kw, object value)
         {
+            string valueAsString = value as string;
             switch (kw)
             {
                 case Keyword.UserID: 
-                    userId = (string)value; break;
-                case Keyword.Password: 
-                    password = (string)value; break;
+                    userId = valueAsString; break;
+                case Keyword.Password:
+                    password = valueAsString; break;
                 case Keyword.Port: 
                     port = ConvertToUInt(value); break;
-                case Keyword.Server: 
-                    server = (string)value; break;
+                case Keyword.Server:
+                    server = valueAsString; break;
                 case Keyword.UseUsageAdvisor: 
                     useUsageAdvisor = ConvertToBool(value); break;
-                case Keyword.CharacterSet: 
-                    charSet = (string)value; break;
+                case Keyword.CharacterSet:
+                    charSet = valueAsString; break;
                 case Keyword.Compress: 
                     compress = ConvertToBool(value); break;
-                case Keyword.PipeName: 
-                    pipeName = (string)value; break;
+                case Keyword.PipeName:
+                    pipeName = valueAsString; break;
                 case Keyword.Logging: 
                     logging = ConvertToBool(value); break;
                 case Keyword.OldSyntax: 
@@ -1290,16 +1293,16 @@
                     if (!clearing)
                         Logger.LogWarning("Use Old Syntax is now obsolete.  Please see
documentation");
                     break;
-                case Keyword.SharedMemoryName: 
-                    sharedMemName = (string)value; break;
+                case Keyword.SharedMemoryName:
+                    sharedMemName = valueAsString; break;
                 case Keyword.AllowBatch: 
                     allowBatch = ConvertToBool(value); break;
                 case Keyword.ConvertZeroDatetime: 
                     convertZeroDatetime = ConvertToBool(value); break;
                 case Keyword.PersistSecurityInfo: 
                     persistSI = ConvertToBool(value); break;
-                case Keyword.Database: 
-                    database = (string)value; break;
+                case Keyword.Database:
+                    database = valueAsString; break;
                 case Keyword.ConnectionTimeout: 
                     connectionTimeout = ConvertToUInt(value); break;
                 case Keyword.Pooling: 
@@ -1335,9 +1338,9 @@
                 case Keyword.TreatBlobsAsUTF8:
                     treatBlobsAsUTF8 = ConvertToBool(value); break;
                 case Keyword.BlobAsUTF8ExcludePattern:
-                    blobAsUtf8ExcludePattern = (string)value; break;
+                    blobAsUtf8ExcludePattern = valueAsString; break;
                 case Keyword.BlobAsUTF8IncludePattern:
-                    blobAsUtf8IncludePattern = (string)value; break;
+                    blobAsUtf8IncludePattern = valueAsString; break;
                 case Keyword.DefaultCommandTimeout:
                     defaultCommandTimeout = ConvertToUInt(value); break;
                 case Keyword.TreatTinyAsBoolean:

Modified: trunk/MySql.Data/Provider/Source/MySqlPool.cs
===================================================================
--- trunk/MySql.Data/Provider/Source/MySqlPool.cs	2008-08-15 16:45:56 UTC (rev 1380)
+++ trunk/MySql.Data/Provider/Source/MySqlPool.cs	2008-08-15 18:16:56 UTC (rev 1381)
@@ -71,8 +71,6 @@
                 idlePool.Enqueue(CreateNewPooledConnection());
 
             procedureCache = new ProcedureCache((int)settings.ProcedureCacheSize);
-
-            beingCleared = false;
         }
 
         #region Properties

Modified: trunk/MySql.Data/Provider/Source/MySqlPoolManager.cs
===================================================================
--- trunk/MySql.Data/Provider/Source/MySqlPoolManager.cs	2008-08-15 16:45:56 UTC (rev
1380)
+++ trunk/MySql.Data/Provider/Source/MySqlPoolManager.cs	2008-08-15 18:16:56 UTC (rev
1381)
@@ -29,18 +29,13 @@
     /// </summary>
     internal class MySqlPoolManager
     {
-        private static Hashtable pools;
+        private static Hashtable pools = new Hashtable();
 #if NET20
         private static List<MySqlPool> clearingPools = new List<MySqlPool>();
 #else
-        private static ArrayList clearingPools;
+        private static ArrayList clearingPools = new ArrayList();
 #endif
 
-        static MySqlPoolManager()
-        {
-            pools = new Hashtable();
-        }
-
         public static MySqlPool GetPool(MySqlConnectionStringBuilder settings)
         {
             string text = settings.GetConnectionString(true);

Modified: trunk/MySql.Data/Provider/Source/Statement.cs
===================================================================
--- trunk/MySql.Data/Provider/Source/Statement.cs	2008-08-15 16:45:56 UTC (rev 1380)
+++ trunk/MySql.Data/Provider/Source/Statement.cs	2008-08-15 18:16:56 UTC (rev 1381)
@@ -124,7 +124,7 @@
 
                     // looks like we might have room for it so we remember the current
end of the stream
                     buffers.RemoveAt(buffers.Count - 1);
-                    long originalLength = packet.Length - 4;
+                    //long originalLength = packet.Length - 4;
 
                     // and attempt to stream the next command
                     string text = batchedCmd.BatchableCommandText;

Modified: trunk/MySql.Data/Provider/Source/StoredProcedure.cs
===================================================================
--- trunk/MySql.Data/Provider/Source/StoredProcedure.cs	2008-08-15 16:45:56 UTC (rev 1380)
+++ trunk/MySql.Data/Provider/Source/StoredProcedure.cs	2008-08-15 18:16:56 UTC (rev 1381)
@@ -127,7 +127,7 @@
             // procedure cache
             string spName = commandText;
             string parameterHash = command.parameterHash;
-            if (spName.IndexOf(".") == -1)
+            if (spName.IndexOf(".", StringComparison.OrdinalIgnoreCase) == -1)
                 spName = Connection.Database + "." + spName;
 
             DataSet ds = GetParameters(spName);

Modified: trunk/MySql.Data/Provider/Source/Types/MySqlDateTime.cs
===================================================================
--- trunk/MySql.Data/Provider/Source/Types/MySqlDateTime.cs	2008-08-15 16:45:56 UTC (rev
1380)
+++ trunk/MySql.Data/Provider/Source/Types/MySqlDateTime.cs	2008-08-15 18:16:56 UTC (rev
1381)
@@ -266,11 +266,12 @@
 		{
 			MySqlDateTime dtValue;
 
+            string valueAsString = value as string;
+
 			if (value is DateTime)
 				dtValue = new MySqlDateTime(type, (DateTime)value);
-			else if (value is string)
-				dtValue = new MySqlDateTime(type, DateTime.Parse((string)value,
-					 System.Globalization.CultureInfo.CurrentCulture));
+			else if (valueAsString != null)
+				dtValue = new MySqlDateTime(type, DateTime.Parse(valueAsString,
CultureInfo.CurrentCulture));
 			else if (value is MySqlDateTime)
 				dtValue = (MySqlDateTime)value;
 			else

Modified: trunk/MySql.Data/Provider/Source/command.cs
===================================================================
--- trunk/MySql.Data/Provider/Source/command.cs	2008-08-15 16:45:56 UTC (rev 1380)
+++ trunk/MySql.Data/Provider/Source/command.cs	2008-08-15 18:16:56 UTC (rev 1381)
@@ -67,9 +67,7 @@
 			cmdType = CommandType.Text;
 			parameters = new MySqlParameterCollection(this);
 			updatedRowSource = UpdateRowSource.Both;
-			cursorPageSize = 0;
 			cmdText = String.Empty;
-			timedOut = false;
 		}
 
 		/// <include file='docs/mysqlcommand.xml' path='docs/ctor2/*'/>

Modified: trunk/MySql.Data/Provider/Source/common/NativeMethods.cs
===================================================================
--- trunk/MySql.Data/Provider/Source/common/NativeMethods.cs	2008-08-15 16:45:56 UTC (rev
1380)
+++ trunk/MySql.Data/Provider/Source/common/NativeMethods.cs	2008-08-15 18:16:56 UTC (rev
1381)
@@ -20,6 +20,7 @@
 
 using System;
 using System.Runtime.InteropServices;
+using System.Threading;
 
 namespace MySql.Data.Common
 {
@@ -56,8 +57,9 @@
 			public bool inheritHandle;
 		}
 
-		[DllImport("Kernel32")]
-		static extern public int CreateFile(String fileName,
+		[DllImport("Kernel32", CharSet=CharSet.Unicode)]
+		static extern public int CreateFile(
+            String fileName,
 			uint desiredAccess,
 			uint shareMode, 
 			SecurityAttributes securityAttributes,
@@ -81,9 +83,8 @@
 
 		[return:MarshalAs(UnmanagedType.Bool)]
 		[DllImport("Kernel32")]
-        static extern public bool WriteFile(IntPtr hFile, [In]byte[] buffer,
-			uint numberOfBytesToWrite, out uint numberOfBytesWritten,
-			IntPtr lpOverlapped);
+        public static extern bool WriteFile(IntPtr hFile, [In]byte[] buffer,
+			uint numberOfBytesToWrite, out uint numberOfBytesWritten, IntPtr lpOverlapped);
 
 		[return:MarshalAs(UnmanagedType.Bool)]
 		[DllImport("kernel32.dll", SetLastError=true)]
@@ -93,12 +94,12 @@
 		[DllImport("kernel32.dll", SetLastError=true)]
 		public static extern bool FlushFileBuffers(IntPtr handle);
 
-        [DllImport("kernel32.dll")]
+        [DllImport("kernel32.dll", CharSet=CharSet.Unicode)]
         public static extern IntPtr OpenEvent(uint dwDesiredAccess,
             [MarshalAs(UnmanagedType.Bool)]bool bInheritHandle,
             string lpName);
 
-        [DllImport("kernel32.dll")]
+        [DllImport("kernel32.dll", CharSet=CharSet.Unicode)]
         public static extern IntPtr OpenFileMapping(uint dwDesiredAccess,
             [MarshalAs(UnmanagedType.Bool)]bool bInheritHandle,
             string lpName);
@@ -109,6 +110,7 @@
             IntPtr dwNumberOfBytesToMap);
 
         [DllImport("kernel32.dll")]
+        [return: MarshalAs(UnmanagedType.Bool)]
         public static extern bool UnmapViewOfFile(IntPtr lpBaseAddress);
 
         [DllImport("kernel32.dll", SetLastError = true)]

Modified: trunk/MySql.Data/Provider/Source/datareader.cs
===================================================================
--- trunk/MySql.Data/Provider/Source/datareader.cs	2008-08-15 16:45:56 UTC (rev 1380)
+++ trunk/MySql.Data/Provider/Source/datareader.cs	2008-08-15 18:16:56 UTC (rev 1381)
@@ -60,7 +60,7 @@
 		 * CommandBehavior.CloseConnection flag. A null reference means
 		 * normal behavior (do not automatically close).
 		 */
-		private MySqlConnection connection = null;
+		private MySqlConnection connection;
 
 		/*
 		 * Because the user should not be able to directly create a 
@@ -75,7 +75,6 @@
 			driver = connection.driver;
 			affectedRows = -1;
 			this.statement = statement;
-			nextResultDone = false;
 			fieldHashCS = new Hashtable();
 			fieldHashCI = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
 		}

Modified: trunk/MySql.Data/Provider/Source/parameter.cs
===================================================================
--- trunk/MySql.Data/Provider/Source/parameter.cs	2008-08-15 16:45:56 UTC (rev 1380)
+++ trunk/MySql.Data/Provider/Source/parameter.cs	2008-08-15 18:16:56 UTC (rev 1381)
@@ -43,7 +43,7 @@
         private const int UNSIGNED_MASK = 0x8000;
         private object paramValue;
         private ParameterDirection direction = ParameterDirection.Input;
-        private bool isNullable = false;
+        private bool isNullable;
         private string paramName;
         private string sourceColumn;
         private DataRowVersion sourceVersion = DataRowVersion.Current;
@@ -321,10 +321,13 @@
             set
             {
                 paramValue = value;
-                if (value is Byte[])
-                    size = (value as Byte[]).Length;
-                else if (value is String)
-                    size = (value as string).Length;
+                byte[] valueAsByte = value as byte[];
+                string valueAsString = value as string;
+
+                if (valueAsByte != null)
+                    size = valueAsByte.Length;
+                else if (valueAsString != null)
+                    size = valueAsString.Length;
                 if (inferType)
                     SetTypeFromValue();
             }

Modified: trunk/MySql.Data/Provider/Source/parameter_collection.cs
===================================================================
--- trunk/MySql.Data/Provider/Source/parameter_collection.cs	2008-08-15 16:45:56 UTC (rev
1380)
+++ trunk/MySql.Data/Provider/Source/parameter_collection.cs	2008-08-15 18:16:56 UTC (rev
1381)
@@ -223,16 +223,15 @@
 		/// <returns>The index of the new <see cref="MySqlParameter"/>
object.</returns>
 		public override int Add(object value)
 		{
-			if (!(value is MySqlParameter))
+            MySqlParameter parameter = value as MySqlParameter;
+			if (parameter == null)
 				throw new MySqlException("Only MySqlParameter objects may be stored");
 
-			MySqlParameter p = (MySqlParameter)value;
-
-			if (p.ParameterName == null || p.ParameterName == String.Empty)
+			if (parameter.ParameterName == null || parameter.ParameterName == String.Empty)
 				throw new MySqlException("Parameters must be named");
 
-			p = Add(p);
-			return IndexOf(p);
+			parameter = Add(parameter);
+			return IndexOf(parameter);
 		}
 
 		/// <summary>
@@ -334,9 +333,10 @@
 		/// <param name="value"></param>
 		public override void Insert(int index, object value)
 		{
-            if (!(value is MySqlParameter))
+            MySqlParameter parameter = value as MySqlParameter;
+            if (parameter == null)
                 throw new MySqlException("Only MySqlParameter objects may be stored");
-            InternalAdd((MySqlParameter)value, index);
+            InternalAdd(parameter, index);
 		}
 
         /// <summary>
@@ -463,7 +463,7 @@
             return value;
         }
 
-        private void AdjustHash(Hashtable hash, string parameterName, int keyIndex, bool
addEntry)
+        private static void AdjustHash(Hashtable hash, string parameterName, int
keyIndex, bool addEntry)
         {
             if (!hash.ContainsKey(parameterName)) return;
             int index = (int)hash[parameterName];

Thread
Connector/NET commit: r1381 - in trunk/MySql.Data/Provider/Source: . Types commonrburnett15 Aug