Improving SchemaBuilder error message

This commit is contained in:
qt1
2014-11-13 12:47:57 -08:00
committed by Sebastien Ros
parent 63e1daa0bd
commit abd91fd2f7

View File

@@ -1,5 +1,6 @@
using System;
using Orchard.Data.Migration.Interpreters;
using Orchard.Localization;
namespace Orchard.Data.Migration.Schema {
public class SchemaBuilder {
@@ -7,10 +8,13 @@ namespace Orchard.Data.Migration.Schema {
private readonly string _featurePrefix;
private readonly Func<string, string> _formatPrefix;
public Localizer T { get; set; }
public SchemaBuilder(IDataMigrationInterpreter interpreter, string featurePrefix = null, Func<string, string> formatPrefix = null) {
_interpreter = interpreter;
_featurePrefix = featurePrefix ?? String.Empty;
_formatPrefix = formatPrefix ?? (s => s ?? String.Empty);
T = NullLocalizer.Instance;
}
public IDataMigrationInterpreter Interpreter {
@@ -46,12 +50,16 @@ namespace Orchard.Data.Migration.Schema {
}
public SchemaBuilder ExecuteSql(string sql, Action<SqlStatementCommand> statement = null) {
var sqlStatmentCommand = new SqlStatementCommand(sql);
if ( statement != null ) {
statement(sqlStatmentCommand);
try {
var sqlStatmentCommand = new SqlStatementCommand(sql);
if (statement != null) {
statement(sqlStatmentCommand);
}
Run(sqlStatmentCommand);
return this;
} catch (Exception ex) {
throw new OrchardException(T("An unexpected error occured while executing the SQL statement: {0}", sql), ex); // Add the sql to the nested exception information
}
Run(sqlStatmentCommand);
return this;
}
private void Run(ISchemaBuilderCommand command) {