Skip to content

Commit

Permalink
Major steps towards v1.0.1
Browse files Browse the repository at this point in the history
 - MERGE support
 - OUTPUT support
 - INSERT ... EXEC support
  • Loading branch information
TaoK committed Aug 10, 2011
1 parent 0b588ef commit d76fd45
Show file tree
Hide file tree
Showing 14 changed files with 523 additions and 149 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.txt
@@ -1,5 +1,12 @@
Poor Man's T-SQL Formatter change log

Version 1.0.1:
--------------
- Added MERGE clause and statement support
- Added OUTPUT and OUTPUT ... INTO ... clause support
- Corrected INSERT ... EXEC parsing/formatting
- Corrected VALUES ... indenting

Version 0.9.13:
--------------
- Added handling of scope resolution operator ("::")
Expand Down
9 changes: 9 additions & 0 deletions PoorMansTSqlFormatterLib/Formatters/TSqlIdentityFormatter.cs
Expand Up @@ -117,6 +117,13 @@ private static void ProcessSqlNode(BaseFormatterState state, XmlElement contentE
case SqlXmlConstants.ENAME_PERMISSIONS_TARGET:
case SqlXmlConstants.ENAME_PERMISSIONS_RECIPIENT:
case SqlXmlConstants.ENAME_DDL_WITH_CLAUSE:
case SqlXmlConstants.ENAME_MERGE_CLAUSE:
case SqlXmlConstants.ENAME_MERGE_TARGET:
case SqlXmlConstants.ENAME_MERGE_USING:
case SqlXmlConstants.ENAME_MERGE_CONDITION:
case SqlXmlConstants.ENAME_MERGE_WHEN:
case SqlXmlConstants.ENAME_MERGE_THEN:
case SqlXmlConstants.ENAME_MERGE_ACTION:
foreach (XmlNode childNode in contentElement.ChildNodes)
{
switch (childNode.NodeType)
Expand Down Expand Up @@ -171,6 +178,7 @@ private static void ProcessSqlNode(BaseFormatterState state, XmlElement contentE
case SqlXmlConstants.ENAME_OTHERKEYWORD:
case SqlXmlConstants.ENAME_DATATYPE_KEYWORD:
case SqlXmlConstants.ENAME_DDL_RETURNS:
case SqlXmlConstants.ENAME_PSEUDONAME:
state.AddOutputContent(contentElement.InnerText, Interfaces.SqlHtmlConstants.CLASS_KEYWORD);
break;

Expand Down Expand Up @@ -242,6 +250,7 @@ public string FormatSQLTokens(Interfaces.ITokenList sqlTokenList)
case SqlTokenType.Number:
case SqlTokenType.BinaryValue:
case SqlTokenType.MonetaryValue:
case SqlTokenType.PseudoName:
outString.Append(entry.Value);
break;
default:
Expand Down
258 changes: 136 additions & 122 deletions PoorMansTSqlFormatterLib/Formatters/TSqlStandardFormatter.cs

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion PoorMansTSqlFormatterLib/Interfaces/SqlTokenType.cs
Expand Up @@ -42,6 +42,7 @@ public enum SqlTokenType
MonetaryValue,
Number,
BinaryValue,
OtherOperator
OtherOperator,
PseudoName
}
}
8 changes: 8 additions & 0 deletions PoorMansTSqlFormatterLib/Interfaces/SqlXmlConstants.cs
Expand Up @@ -81,7 +81,15 @@ public static class SqlXmlConstants
public const string ENAME_CONTAINER_GENERALCONTENT = "ContainerContentBody";
public const string ENAME_CONTAINER_CLOSE = "ContainerClose";
public const string ENAME_SELECTIONTARGET = "SelectionTarget";
public const string ENAME_MERGE_CLAUSE = "MergeClause";
public const string ENAME_MERGE_TARGET = "MergeTarget";
public const string ENAME_MERGE_USING = "MergeUsing";
public const string ENAME_MERGE_CONDITION = "MergeCondition";
public const string ENAME_MERGE_WHEN = "MergeWhen";
public const string ENAME_MERGE_THEN = "MergeThen";
public const string ENAME_MERGE_ACTION = "MergeAction";

public const string ENAME_PSEUDONAME = "PseudoName";
public const string ENAME_WHITESPACE = "WhiteSpace";
public const string ENAME_OTHERNODE = "Other";
public const string ENAME_COMMENT_SINGLELINE = "SingleLineComment";
Expand Down
15 changes: 15 additions & 0 deletions PoorMansTSqlFormatterLib/ParseTree.cs
Expand Up @@ -132,6 +132,16 @@ internal void EscapeAnyBetweenConditions()
}
}

internal void EscapeMergeAction()
{
if (PathNameMatches(0, SqlXmlConstants.ENAME_SQL_CLAUSE)
&& PathNameMatches(1, SqlXmlConstants.ENAME_SQL_STATEMENT)
&& PathNameMatches(2, SqlXmlConstants.ENAME_MERGE_ACTION)
&& HasNonWhiteSpaceNonCommentContent(CurrentContainer)
)
MoveToAncestorContainer(4);
}

internal void EscapePartialStatementContainers()
{
if (PathNameMatches(0, SqlXmlConstants.ENAME_SQL_CLAUSE)
Expand Down Expand Up @@ -161,6 +171,9 @@ internal void EscapePartialStatementContainers()
)
)
MoveToAncestorContainer(3);
else if (PathNameMatches(0, SqlXmlConstants.ENAME_MERGE_WHEN))
MoveToAncestorContainer(2);

}

internal void EscapeAnySingleOrPartialStatementContainers()
Expand All @@ -170,6 +183,7 @@ internal void EscapeAnySingleOrPartialStatementContainers()

if (HasNonWhiteSpaceNonCommentContent(CurrentContainer))
{
EscapeMergeAction();
EscapePartialStatementContainers();

while (true)
Expand Down Expand Up @@ -308,6 +322,7 @@ internal void ConsiderStartingNewClause()
{
EscapeAnySelectionTarget();
EscapeAnyBetweenConditions();
EscapePartialStatementContainers();

if (CurrentContainer.Name.Equals(SqlXmlConstants.ENAME_SQL_CLAUSE)
&& HasNonWhiteSpaceNonSingleCommentContent(CurrentContainer)
Expand Down

0 comments on commit d76fd45

Please sign in to comment.