List:Commits« Previous MessageNext Message »
From:rburnett Date:September 1 2007 12:08am
Subject:Connector/NET commit: r999 - in branches/5.1/VisualStudio: . Descriptors
View as plain text  
Modified:
   branches/5.1/VisualStudio/Descriptors/CollationDescriptor.cs
   branches/5.1/VisualStudio/Descriptors/ColumnDescriptor.cs
   branches/5.1/VisualStudio/Descriptors/EngineDescriptor.cs
   branches/5.1/VisualStudio/Descriptors/RootDescriptor.cs
   branches/5.1/VisualStudio/MySqlConnectionSupport.cs
   branches/5.1/VisualStudio/MySqlDataSourceInformation.cs
Log:
fixed several problems with VS integration and working with MySQL 4.1.  The biggest problem was when you created a connection to a 5.0 server, stopped the server, deleted the connection, started a 4.1 server, and then remade the connection.  The package would still attempt to use cached metadata for the 5.0 server.

Also added some workarounds for the infamous binary metadata issue of MySQL

Modified: branches/5.1/VisualStudio/Descriptors/CollationDescriptor.cs
===================================================================
--- branches/5.1/VisualStudio/Descriptors/CollationDescriptor.cs	2007-08-30 22:24:37 UTC (rev 998)
+++ branches/5.1/VisualStudio/Descriptors/CollationDescriptor.cs	2007-08-31 22:08:45 UTC (rev 999)
@@ -142,8 +142,11 @@
                 throw new ArgumentNullException("connection");
 
             // Use base method to read table
-            DataTable result = base.ReadTable(connection, restrictions, sort);
+            DataTable first_result = base.ReadTable(connection, restrictions, sort);
 
+			// fixup collation names
+			DataTable result = MySqlConnectionSupport.ConvertAllBinaryColumns(first_result);
+
             // If there is now result from bas, return immediately
             if (result == null)
                 return result;

Modified: branches/5.1/VisualStudio/Descriptors/ColumnDescriptor.cs
===================================================================
--- branches/5.1/VisualStudio/Descriptors/ColumnDescriptor.cs	2007-08-30 22:24:37 UTC (rev 998)
+++ branches/5.1/VisualStudio/Descriptors/ColumnDescriptor.cs	2007-08-31 22:08:45 UTC (rev 999)
@@ -110,7 +110,7 @@
             [Field(OptionName = OrdinalOption, FieldType = TypeCode.Int64)]
             public const string Ordinal = "ORDINAL_POSITION";
             [Field(FieldType = TypeCode.String)]
-            public const string Default = "TRUE_DEFAULT";
+            public const string Default = "COLUMN_DEFAULT";
             [Field(FieldType = TypeCode.Boolean)]
             public const string Nullable = "IS_NULLABLE";
             [Field(OptionName = DataTypeOption, FieldType = TypeCode.String)]

Modified: branches/5.1/VisualStudio/Descriptors/EngineDescriptor.cs
===================================================================
--- branches/5.1/VisualStudio/Descriptors/EngineDescriptor.cs	2007-08-30 22:24:37 UTC (rev 998)
+++ branches/5.1/VisualStudio/Descriptors/EngineDescriptor.cs	2007-08-31 22:08:45 UTC (rev 999)
@@ -90,22 +90,7 @@
         {
             DataTable dt = base.ReadTable(connection, restrictions, sort);
 
-            // stupid hack to work around the issue that show engines returns 
-            // everything as byte[]
-            DataTable newDT = dt.Clone();
-            foreach (DataColumn column in newDT.Columns)
-                column.DataType = typeof(System.String);
-
-            Encoding e = Encoding.GetEncoding("latin1");
-            foreach (DataRow row in dt.Rows)
-            {
-                DataRow newRow = newDT.NewRow();
-                newRow[0] = e.GetString((byte[])row[0]);
-                newRow[1] = e.GetString((byte[])row[1]);
-                newRow[2] = e.GetString((byte[])row[2]);
-                newDT.Rows.Add(newRow);
-            }
-            return newDT;
+			return MySqlConnectionSupport.ConvertAllBinaryColumns(dt);
         }
     }
 }

Modified: branches/5.1/VisualStudio/Descriptors/RootDescriptor.cs
===================================================================
--- branches/5.1/VisualStudio/Descriptors/RootDescriptor.cs	2007-08-30 22:24:37 UTC (rev 998)
+++ branches/5.1/VisualStudio/Descriptors/RootDescriptor.cs	2007-08-31 22:08:45 UTC (rev 999)
@@ -109,7 +109,7 @@
                 return base.GetDefaultRestrictions(connection);
 
             // For legacy version return array with current conection information
-            return new string[] { connection.ServerName, "'" + connection.Schema + "'" };
+            return new string[] { "'" + connection.ServerName + "'", "'" + connection.Schema + "'" };
         }
 
         /// <summary>

Modified: branches/5.1/VisualStudio/MySqlConnectionSupport.cs
===================================================================
--- branches/5.1/VisualStudio/MySqlConnectionSupport.cs	2007-08-30 22:24:37 UTC (rev 998)
+++ branches/5.1/VisualStudio/MySqlConnectionSupport.cs	2007-08-31 22:08:45 UTC (rev 999)
@@ -27,6 +27,7 @@
 using Microsoft.VisualStudio.Data.AdoDotNet;
 using System.Globalization;
 using MySql.Data.VisualStudio.Properties;
+using System.Text;
 
 
 namespace MySql.Data.VisualStudio
@@ -42,7 +43,9 @@
         /// Simple constructor
         /// </summary>
         public MySqlConnectionSupport()
-            : base(MySqlConnectionProperties.Names.InvariantProviderName) { } 
+            : base(MySqlConnectionProperties.Names.InvariantProviderName) 
+		{
+		} 
         #endregion
 
         #region Overridden methods
@@ -66,6 +69,7 @@
                 // connection is OK, just close it normaly
                 providerObjectVal.Close();
             }
+			base.Close();
         }
 
         /// <summary>
@@ -128,6 +132,8 @@
             }
 
             // Rreturn true if everything is ok
+			if (sourceInformation != null)
+				sourceInformation.Refresh();
             return true;
         }
 
@@ -152,7 +158,7 @@
                 }
                 return viewSupport;
             }
-            if (serviceType == typeof(DataObjectSupport))
+            else if (serviceType == typeof(DataObjectSupport))
             {
                 if (objectSupport == null)
                 {
@@ -160,7 +166,7 @@
                 }
                 return objectSupport;
             }
-            if (serviceType == typeof(DataSourceInformation))
+            else if (serviceType == typeof(DataSourceInformation))
             {
                 if (sourceInformation == null)
                 {
@@ -168,8 +174,7 @@
                 }
                 return sourceInformation;
             }
-            object result = base.GetServiceImpl(serviceType);
-            return result;
+			else return base.GetServiceImpl(serviceType);
         }
         
         /// <summary>
@@ -296,7 +301,33 @@
         #region Support entities
         private DataViewSupport viewSupport;
         private DataObjectSupport objectSupport;
-        private DataSourceInformation sourceInformation;
+        private MySqlDataSourceInformation sourceInformation;
         #endregion
+
+		internal static DataTable ConvertAllBinaryColumns(DataTable dt)
+		{
+			// stupid hack to work around the issue that show engines returns 
+			// everything as byte[]
+			DataTable newDT = dt.Clone();
+
+			foreach (DataColumn column in newDT.Columns)
+				if (column.DataType == typeof(System.Byte[]))
+					column.DataType = typeof(System.String);
+
+			Encoding e = Encoding.GetEncoding("latin1");
+			foreach (DataRow row in dt.Rows)
+			{
+				DataRow newRow = newDT.NewRow();
+				foreach (DataColumn column in dt.Columns)
+				{
+					if (column.DataType == typeof(System.Byte[]))
+						newRow[column.Ordinal] = e.GetString((byte[])row[column.Ordinal]);
+					else
+						newRow[column.Ordinal] = row[column.Ordinal];
+				}
+				newDT.Rows.Add(newRow);
+			}
+			return newDT;
+		}
     }
 }

Modified: branches/5.1/VisualStudio/MySqlDataSourceInformation.cs
===================================================================
--- branches/5.1/VisualStudio/MySqlDataSourceInformation.cs	2007-08-30 22:24:37 UTC (rev 998)
+++ branches/5.1/VisualStudio/MySqlDataSourceInformation.cs	2007-08-31 22:08:45 UTC (rev 999)
@@ -21,6 +21,8 @@
 using System;
 using Microsoft.VisualStudio.Data;
 using Microsoft.VisualStudio.Data.AdoDotNet;
+using System.Data;
+using System.Data.Common;
 
 namespace MySql.Data.VisualStudio
 {
@@ -30,7 +32,8 @@
 	public class MySqlDataSourceInformation : AdoDotNetDataSourceInformation
 	{
         #region Properties names
-        public const string DataSource = "DataSource";        
+        public const string DataSource = "DataSource";
+		private DataTable values;
         #endregion
 
         #region Constructor
@@ -42,6 +45,7 @@
             : base(connection)
         {
             AddProperty(DataSource);
+			AddProperty(DataSourceVersion);
             AddProperty(DefaultSchema);
             AddProperty(SupportsAnsi92Sql, true);
             AddProperty(SupportsQuotedIdentifierParts, true);
@@ -59,7 +63,32 @@
         } 
         #endregion
 
+		internal void Refresh()
+		{
+			DbConnection c = (DbConnection)Connection.GetLockedProviderObject();
+			values = c.GetSchema("DataSourceInformation");
+			Connection.UnlockProviderObject();
+		}
+
         #region Value retrieving
+
+		public override object this[string propertyName]
+		{
+			get
+			{
+				// data source version can change so we need to 
+				// refresh it here
+				if (propertyName == "DataSourceVersion")
+				{
+					if (values == null)
+						Refresh();
+					return values.Rows[0]["DataSourceProductVersion"];
+				}
+				else
+					return base[propertyName];
+			}
+		}
+
         /// <summary>
         /// Called to retrieve property value. Supports following custom properties:
         /// DataSource @@ -77,7 +106,8 @@
             {
                 return ConnectionWrapper.Schema;
             }
-            return base.RetrieveValue(propertyName);
+            object value = base.RetrieveValue(propertyName);
+			return value;
         } 
         #endregion
 

Thread
Connector/NET commit: r999 - in branches/5.1/VisualStudio: . Descriptorsrburnett1 Sep