Skip to content

Commit cb0cf41

Browse files
committed
Do not ignore SET statements when collecting DML command text
1 parent 1ad84ae commit cb0cf41

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

src/Dibix.Sdk/CodeGeneration/Formatter/SqlStatementFormatter.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
43
using Dibix.Sdk.Sql;
54
using Microsoft.SqlServer.TransactSql.ScriptDom;
65

@@ -9,12 +8,7 @@ namespace Dibix.Sdk.CodeGeneration
98
public abstract class SqlStatementFormatter : ISqlStatementFormatter
109
{
1110
protected const int Indentation = 4;
12-
13-
private static readonly Type[] ExcludedTypes =
14-
{
15-
typeof(PredicateSetStatement)
16-
};
17-
11+
1812
public bool StripWhiteSpace { get; set; }
1913

2014
FormattedSqlStatement ISqlStatementFormatter.Format(SqlStatementDefinition statementDefinition, StatementList statementList)
@@ -28,7 +22,7 @@ FormattedSqlStatement ISqlStatementFormatter.Format(SqlStatementDefinition state
2822

2923
protected void CollectStatements(StatementList statementList, Action<TSqlStatement, int, int> statementHandler, Action<TSqlParserToken> tokenHandler = null)
3024
{
31-
IList<TSqlStatement> statements = GetStatements(statementList).ToArray();
25+
IList<TSqlStatement> statements = statementList.Statements;
3226
for (int i = 0; i < statements.Count; i++)
3327
{
3428
TSqlStatement statement = statements[i];
@@ -58,9 +52,5 @@ protected void CollectStatements(StatementList statementList, Action<TSqlStateme
5852
statementHandler(statement, i, statements.Count);
5953
}
6054
}
61-
62-
private static IEnumerable<TSqlStatement> GetStatements(StatementList statementList) => statementList.Statements.Where(FilterStatement);
63-
64-
private static bool FilterStatement(TSqlStatement statement) => !ExcludedTypes.Any(statement.GetType().IsAssignableFrom);
6555
}
6656
}

src/Dibix.Sdk/CodeGeneration/Model/CodeGenerationModelLoader.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ string projectName
7272
bool requireExplicitMarkup = !isEmbedded;
7373
ISqlStatementParser parser = new SqlStoredProcedureParser(requireExplicitMarkup);
7474
Lazy<TSqlModel> modelAccessor = sqlModel != null ? new Lazy<TSqlModel>(() => sqlModel) : new Lazy<TSqlModel>(() => PublicSqlDataSchemaModelLoader.Load(projectName, databaseSchemaProviderName, modelCollation, source, sqlReferencePath, logger));
75-
ISqlStatementFormatter formatter = isEmbedded ? (ISqlStatementFormatter)new TakeSourceSqlStatementFormatter() : new ExecStoredProcedureSqlStatementFormatter();
75+
ISqlStatementFormatter formatter = SelectSqlStatementFormatter(isEmbedded);
7676
formatter.StripWhiteSpace = model.CommandTextFormatting == CommandTextFormatting.StripWhiteSpace;
7777
IDictionary<string, SecurityScheme> securitySchemeMap = new Dictionary<string, SecurityScheme>();
7878

@@ -99,5 +99,13 @@ string projectName
9999

100100
return model;
101101
}
102+
103+
private static ISqlStatementFormatter SelectSqlStatementFormatter(bool isEmbedded)
104+
{
105+
if (isEmbedded)
106+
return new TakeSourceSqlStatementFormatter();
107+
108+
return new ExecStoredProcedureSqlStatementFormatter();
109+
}
102110
}
103111
}

0 commit comments

Comments
 (0)