Fixes: U4-7090 Upgrade error with dates

This commit is contained in:
Shannon
2015-09-11 11:49:37 +02:00
parent 647c7a6ce0
commit 4bb89c1827
4 changed files with 33 additions and 0 deletions

View File

@@ -76,6 +76,8 @@ namespace Umbraco.Core.Persistence.Migrations
case TypeCode.UInt32:
case TypeCode.UInt64:
return val.ToString();
case TypeCode.DateTime:
return SqlSyntax.FormatDateTime((DateTime) val);
default:
return SqlSyntaxContext.SqlSyntaxProvider.GetQuotedValue(val.ToString());
}

View File

@@ -54,6 +54,7 @@ namespace Umbraco.Core.Persistence.SqlSyntax
string DeleteConstraint { get; }
string CreateForeignKeyConstraint { get; }
string DeleteDefaultConstraint { get; }
string FormatDateTime(DateTime date, bool includeTime = true);
string Format(TableDefinition table);
string Format(IEnumerable<ColumnDefinition> columns);
List<string> Format(IEnumerable<IndexDefinition> indexes);

View File

@@ -191,6 +191,21 @@ ORDER BY TABLE_NAME, INDEX_NAME",
return false;
}
/// <summary>
/// This is used ONLY if we need to format datetime without using SQL parameters (i.e. during migrations)
/// </summary>
/// <param name="date"></param>
/// <param name="includeTime"></param>
/// <returns></returns>
/// <remarks>
/// MySQL has a DateTime standard that is unambiguous and works on all servers:
/// YYYYMMDDHHMMSS
/// </remarks>
public override string FormatDateTime(DateTime date, bool includeTime = true)
{
return includeTime ? date.ToString("YYYYMMDDHHmmss") : date.ToString("YYYYMMDD");
}
public override string GetQuotedTableName(string tableName)
{
return string.Format("`{0}`", tableName);

View File

@@ -251,6 +251,21 @@ namespace Umbraco.Core.Persistence.SqlSyntax
return true;
}
/// <summary>
/// This is used ONLY if we need to format datetime without using SQL parameters (i.e. during migrations)
/// </summary>
/// <param name="date"></param>
/// <param name="includeTime"></param>
/// <returns></returns>
/// <remarks>
/// MSSQL has a DateTime standard that is unambiguous and works on all servers:
/// YYYYMMDD HH:mm:ss
/// </remarks>
public virtual string FormatDateTime(DateTime date, bool includeTime = true)
{
return includeTime ? date.ToString("YYYYMMDD HH:mm:ss") : date.ToString("YYYYMMDD");
}
public virtual string Format(TableDefinition table)
{
var statement = string.Format(CreateTable, GetQuotedTableName(table.Name), Format(table.Columns));