Fix MySql support

Fixes #7565 
Fixes #7570 
Fixes #7570
Fixes #5366
Fixes #7571 
Fixes #4779
This commit is contained in:
siyamandayubi
2017-03-02 21:52:28 +01:00
committed by Sébastien Ros
parent 6f39308741
commit 0e3b8ad32d
3 changed files with 50 additions and 17 deletions

View File

@@ -428,7 +428,7 @@ namespace Orchard.Data.Migration.Interpreters {
case TypeCode.Decimal:
return Convert.ToString(value, CultureInfo.InvariantCulture);
case TypeCode.DateTime:
return String.Concat("'", Convert.ToString(value, CultureInfo.InvariantCulture), "'");
return String.Concat("'", ((DateTime)value).ToString("yyyy-MM-dd hh:mm:ss", CultureInfo.InvariantCulture), "'");
}
return "null";

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using NHibernate.Dialect;
using Orchard.Data.Migration.Schema;
@@ -8,12 +9,14 @@ using Orchard.Environment.Configuration;
using Orchard.Localization;
namespace Orchard.Data.Migration.Interpreters {
public class MySqlCommandInterpreter : ICommandInterpreter<AlterColumnCommand> {
public class MySqlCommandInterpreter : ICommandInterpreter<AlterColumnCommand>, ICommandInterpreter<AddIndexCommand> {
private readonly Lazy<Dialect> _dialectLazy;
private readonly ShellSettings _shellSettings;
private readonly ITransactionManager _transactionManager;
private readonly DefaultDataMigrationInterpreter _dataMigrationInterpreter;
public MySqlCommandInterpreter(DefaultDataMigrationInterpreter dataMigrationInterpreter) {
public MySqlCommandInterpreter(DefaultDataMigrationInterpreter dataMigrationInterpreter, ITransactionManager transactionManager) {
_transactionManager = transactionManager;
_dataMigrationInterpreter = dataMigrationInterpreter;
T = NullLocalizer.Instance;
}
@@ -26,9 +29,11 @@ namespace Orchard.Data.Migration.Interpreters {
public MySqlCommandInterpreter(
ShellSettings shellSettings,
ISessionFactoryHolder sessionFactoryHolder) {
_shellSettings = shellSettings;
_dialectLazy = new Lazy<Dialect>(() => Dialect.GetDialect(sessionFactoryHolder.GetConfiguration().Properties));
ISessionFactoryHolder sessionFactoryHolder,
ITransactionManager transactionManager) {
_shellSettings = shellSettings;
_transactionManager = transactionManager;
_dialectLazy = new Lazy<Dialect>(() => Dialect.GetDialect(sessionFactoryHolder.GetConfiguration().Properties));
}
public string[] CreateStatements(AlterColumnCommand command) {
@@ -42,8 +47,7 @@ namespace Orchard.Data.Migration.Interpreters {
// type
if (command.DbType != DbType.Object) {
builder.Append(DefaultDataMigrationInterpreter.GetTypeName(_dialectLazy.Value, command.DbType, command.Length, command.Precision, command.Scale));
}
else {
} else {
if (command.Length > 0 || command.Precision > 0 || command.Scale > 0) {
throw new OrchardException(T("Error while executing data migration: you need to specify the field's type in order to change its properties"));
}
@@ -64,13 +68,11 @@ namespace Orchard.Data.Migration.Interpreters {
// result
var result = new List<string>();
if (builder.Length > initLength)
{
if (builder.Length > initLength) {
result.Add(builder.ToString());
}
if (builder2.Length > initLength2)
{
if (builder2.Length > initLength2) {
result.Add(builder2.ToString());
}
@@ -82,5 +84,36 @@ namespace Orchard.Data.Migration.Interpreters {
return tableName;
return _shellSettings.DataTablePrefix + "_" + tableName;
}
public string[] CreateStatements(AddIndexCommand command) {
var session = _transactionManager.GetSession();
using (var sqlCommand = session.Connection.CreateCommand()) {
var columnNames = String.Join(", ", command.ColumnNames.Select(c => string.Format("'{0}'", c)));
var tableName = PrefixTableName(command.TableName);
// check whether the index contains big nvarchar columns or text fields
string sql = @"SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = '{1}' AND COLUMN_NAME in ({0}) AND TABLE_SCHEMA = '{2}' AND
((Data_type = 'varchar' and CHARACTER_MAXIMUM_LENGTH > 767) OR data_type= 'text');";
sql = string.Format(sql, columnNames, tableName, session.Connection.Database);
sqlCommand.CommandText = sql;
var columnList = command.ColumnNames.ToList();
using (var reader = sqlCommand.ExecuteReader()) {
// Provide prefix for string columns with length longer than 767
while (reader.Read()) {
var columnName = reader.GetString(0);
columnList[columnList.IndexOf(columnName)] = string.Format("{0}(767)", columnName);
}
}
return new[] {string.Format("create index {1} on {0} ({2}) ",
_dialectLazy.Value.QuoteForTableName(tableName),
_dialectLazy.Value.QuoteForTableName(PrefixTableName(command.IndexName)),
String.Join(", ", columnList))};
}
}
}
}