List:Commits« Previous MessageNext Message »
From:Reggie Burnett Date:November 17 2010 10:59pm
Subject:bzr commit into connector-net-trunk branch (reggie.burnett:943)
View as plain text  
#At file:///C:/work/connector-net/trunk/ based on revid:reggie.burnett@stripped

  943 Reggie Burnett	2010-11-17 [merge]
      merged

    modified:
      MySql.Data/Provider/Source/ISSchemaProvider.cs
      MySql.Data/Provider/Source/SchemaProvider.cs
      MySql.Data/Provider/Source/Types/MetaData.cs
      MySql.Data/Tests/Source/GetSchemaTests.cs
=== modified file 'MySql.Data/Provider/Source/ISSchemaProvider.cs'
=== modified file 'MySql.Data/Provider/Source/ISSchemaProvider.cs'
--- a/MySql.Data/Provider/Source/ISSchemaProvider.cs	2010-11-03 21:04:38 +0000
+++ b/MySql.Data/Provider/Source/ISSchemaProvider.cs	2010-11-17 22:57:36 +0000
@@ -119,6 +119,7 @@
             DataTable dt = Query("COLUMNS", null, keys, restrictions);
             dt.Columns.Remove("CHARACTER_OCTET_LENGTH");
             dt.TableName = "Columns";
+            QuoteDefaultValues(dt);
             return dt;
         }
 
@@ -164,6 +165,7 @@
             dt.Columns[0].ColumnName = "VIEW_CATALOG";
             dt.Columns[1].ColumnName = "VIEW_SCHEMA";
             dt.Columns[2].ColumnName  = "VIEW_NAME";
+            QuoteDefaultValues(dt);
             return dt;
         }
 

=== modified file 'MySql.Data/Provider/Source/SchemaProvider.cs'
--- a/MySql.Data/Provider/Source/SchemaProvider.cs	2010-08-18 19:48:34 +0000
+++ b/MySql.Data/Provider/Source/SchemaProvider.cs	2010-11-17 22:56:48 +0000
@@ -142,6 +142,19 @@
             return dt;
         }
 
+        protected void QuoteDefaultValues(DataTable dt)
+        {
+            if (dt == null) return;
+            if (!dt.Columns.Contains("COLUMN_DEFAULT")) return;
+
+            foreach (DataRow row in dt.Rows)
+            {
+                object defaultValue = row["COLUMN_DEFAULT"];
+                if (MetaData.IsTextType(row["DATA_TYPE"].ToString()))
+                    row["COLUMN_DEFAULT"] = String.Format("'{0}'", defaultValue);
+            }
+        }
+
         public virtual DataTable GetColumns(string[] restrictions)
         {
             DataTable dt = new DataTable("Columns");
@@ -178,6 +191,7 @@
                 LoadTableColumns(dt, row["TABLE_SCHEMA"].ToString(),
                                  row["TABLE_NAME"].ToString(), columnName);
 
+            QuoteDefaultValues(dt);
             return dt;
         }
 

=== modified file 'MySql.Data/Provider/Source/Types/MetaData.cs'
--- a/MySql.Data/Provider/Source/Types/MetaData.cs	2010-08-18 19:48:34 +0000
+++ b/MySql.Data/Provider/Source/Types/MetaData.cs	2010-11-17 22:56:48 +0000
@@ -51,6 +51,26 @@
             return false;
         }
 
+        public static bool IsTextType(string typename)
+        {
+            string lowerType = typename.ToLower(CultureInfo.InvariantCulture);
+            switch (lowerType)
+            {
+                case "varchar":
+                case "char":
+                case "text":
+                case "longtext":
+                case "tinytext":
+                case "mediumtext":
+                case "nchar":
+                case "nvarchar": 
+                case "enum":
+                case "set":
+                return true;
+            }
+            return false;
+        }
+
         public static bool SupportScale(string typename)
         {
             string lowerType = typename.ToLower(CultureInfo.InvariantCulture);

=== modified file 'MySql.Data/Tests/Source/GetSchemaTests.cs'
--- a/MySql.Data/Tests/Source/GetSchemaTests.cs	2010-08-18 19:52:04 +0000
+++ b/MySql.Data/Tests/Source/GetSchemaTests.cs	2010-11-17 22:57:36 +0000
@@ -185,14 +185,15 @@
 		[Test]
 		public void Columns()
 		{
-			execSQL("CREATE TABLE test (col1 int, col2 decimal(20,5), " +
-				"col3 varchar(50) character set utf8, col4 tinyint unsigned)");
+			execSQL(@"CREATE TABLE test (col1 int, col2 decimal(20,5), 
+				col3 varchar(50) character set utf8, col4 tinyint unsigned, 
+                col5 varchar(20) default 'boo')");
 
 			string[] restrictions = new string[4];
 			restrictions[1] = database0;
 			restrictions[2] = "test";
 			DataTable dt = conn.GetSchema("Columns", restrictions);
-			Assert.AreEqual(4, dt.Rows.Count);
+			Assert.AreEqual(5, dt.Rows.Count);
 			Assert.AreEqual("Columns", dt.TableName);
             if (Version.Major >= 5 && Version.Minor >= 1)
             {
@@ -233,7 +234,16 @@
 			Assert.AreEqual(4, dt.Rows[3]["ORDINAL_POSITION"]);
 			Assert.AreEqual("YES", dt.Rows[3]["IS_NULLABLE"]);
 			Assert.AreEqual("TINYINT", dt.Rows[3]["DATA_TYPE"].ToString().ToUpper());
-		}
+
+            // fifth column
+            Assert.AreEqual(database0.ToUpper(), dt.Rows[4]["TABLE_SCHEMA"].ToString().ToUpper());
+            Assert.AreEqual("COL5", dt.Rows[4]["COLUMN_NAME"].ToString().ToUpper());
+            Assert.AreEqual(5, dt.Rows[4]["ORDINAL_POSITION"]);
+            Assert.AreEqual("YES", dt.Rows[4]["IS_NULLABLE"]);
+            Assert.AreEqual("VARCHAR", dt.Rows[4]["DATA_TYPE"].ToString().ToUpper());
+            Assert.AreEqual("VARCHAR(20)", dt.Rows[4]["COLUMN_TYPE"].ToString().ToUpper());
+            Assert.AreEqual("'BOO'", dt.Rows[4]["COLUMN_DEFAULT"].ToString().ToUpper());
+        }
 
         /// <summary> 
         /// Bug #46270 connection.GetSchema("Columns") fails on MySQL 4.1  


Attachment: [text/bzr-bundle] bzr/reggie.burnett@oracle.com-20101117225858-s8ggrb7z8krar3no.bundle
Thread
bzr commit into connector-net-trunk branch (reggie.burnett:943) Reggie Burnett17 Nov