sougatamondal / migratordotnet

Automatically exported from code.google.com/p/migratordotnet
0 stars 0 forks source link

Patch to correct quoted values in MySql #90

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Index: src/Migrator.Providers/Impl/Mysql/MysqlDialect.cs
===================================================================
--- src/Migrator.Providers/Impl/Mysql/MysqlDialect.cs   (revisión: 129)
+++ src/Migrator.Providers/Impl/Mysql/MysqlDialect.cs   (copia de trabajo)
@@ -57,11 +57,13 @@

         public override string Default(object defaultValue)
         {
-            if (defaultValue.GetType().Equals(typeof (bool)))
+            if (defaultValue == null)
+                return "null";
+            else if (defaultValue.GetType().Equals(typeof (bool)))
             {
                 defaultValue = ((bool) defaultValue) ? 1 : 0;
             }
-            return String.Format("DEFAULT {0}", defaultValue);
+            return String.Format("DEFAULT '{0}'", defaultValue);
         }
     }
 }
\ No newline at end of file
Index: src/Migrator.Providers/Impl/Mysql/MySqlTransformationProvider.cs
===================================================================
--- src/Migrator.Providers/Impl/Mysql/MySqlTransformationProvider.cs
(revisión: 129)
+++ src/Migrator.Providers/Impl/Mysql/MySqlTransformationProvider.cs    (copia
de trabajo)
@@ -114,7 +114,21 @@
             string sqlCreate = string.Format("CREATE TABLE {0} ({1})
ENGINE = {2}", name, columns, engine);
             ExecuteNonQuery(sqlCreate);
         }
-        
+
+        public override string[] QuoteValues(string[] values)
+        {
+            return Array.ConvertAll<string, string>(values,
+                delegate(string val) 
+                {
+                    if (val == null)
+                        return "NULL";
+                    //else if (val.Length > 2 && val.Substring(0, 2) == "0x") 
+                    //    return val;
+                    else
+                        return String.Format("'{0}'", val.Replace("'",
"''")); 
+                });
+        }
+
         public override void RenameColumn(string tableName, string
oldColumnName, string newColumnName)
         {
             if (ColumnExists(tableName, newColumnName))

Original issue reported on code.google.com by andresmo...@gmail.com on 10 Feb 2009 at 1:25

GoogleCodeExporter commented 8 years ago
Automatically quoting a value in default value will prevent you from using 
functions
as a default value (such as the date() function for the current date).

Original comment by geoffl...@gmail.com on 20 Mar 2009 at 1:40