Trivadis / plsql-formatter-settings

PL/SQL & SQL formatter settings based on the Trivadis PL/SQL & SQL Coding Guidelines
Apache License 2.0
134 stars 46 forks source link

Add - Formatierung "CASE WHEN" in SELECT statemen #254

Closed chatelao closed 1 year ago

chatelao commented 1 year ago

IS:

SELECT job_id
     , CASE
   WHEN job_id = 'AD_PRES' THEN '123'
   WHEN job_id = 'IT_PROG' THEN '456'
   ELSE '059'
         END case_test
  FROM employees

WOULD LIKE:

SELECT job_id
     , CASE
        WHEN job_id = 'AD_PRES' THEN '123'
        WHEN job_id = 'IT_PROG' THEN '456'
        ELSE '059'
       END case_test
  FROM employees

MicrosoftTeams-image (4)

PhilippSalvisberg commented 1 year ago

With your Advanced Format settingsmy SQL Developer 23.1 produces this result

SELECT job_id
     , CASE
           WHEN job_id = 'AD_PRES' THEN
               '123'
           WHEN job_id = 'IT_PROG' THEN
               '456'
           ELSE
               '059'
       END case_test
FROM employees

That looks good.

I suspect that you use another Arbori program (Custom Format) than the one provided in this repository.

Custom Format should look like this

image

Please follow the installation instructions.

Please note that every version of SQL Developer requires a matching Arbori program. This is the one for SQL Developer 23.1.

chatelao commented 1 year ago

You are (again) totally right. I saw the name "Salvis" and assumed to have the right file loaded:

image

chatelao commented 1 year ago

I'm really sorry, but even with the new "arbori" the problem persists:

image

Here my configuration as .xml:

<options>
<adjustCaseOnly>false</adjustCaseOnly>
<alignTabColAliases>false</alignTabColAliases>
<breakOnSubqueries>true</breakOnSubqueries>
<alignEquality>false</alignEquality>
<breakAfterElsif>false</breakAfterElsif>
<formatWhenSyntaxError>false</formatWhenSyntaxError>
<singleLineComments>oracle.dbtools.app.Format.InlineComments.CommentsUnchanged</singleLineComments>
<breakAnsiiJoin>true</breakAnsiiJoin>
<maxCharLineSize>120</maxCharLineSize>
<alignAssignments>true</alignAssignments>
<brkCtrIndentedConditionsActions>false</brkCtrIndentedConditionsActions>
<breaksProcArgs>true</breaksProcArgs>
<alignRight>true</alignRight>
<breaksComma>oracle.dbtools.app.Format.Breaks.Before</breaksComma>
<breaksAroundLogicalConjunctions>oracle.dbtools.app.Format.Breaks.Before</breaksAroundLogicalConjunctions>
<breakAfterWhen>false</breakAfterWhen>
<brkCtrlIndentedActions>true</brkCtrlIndentedActions>
<alignNamedArgs>true</alignNamedArgs>
<formatProgramURL>default</formatProgramURL>
<formatThreshold>1</formatThreshold>
<spaceAroundOperators>true</spaceAroundOperators>
<useTab>false</useTab>
<idCase>oracle.dbtools.app.Format.Case.NoCaseChange</idCase>
<extraLinesAfterSignificantStatements>oracle.dbtools.app.Format.BreaksX2.Keep</extraLinesAfterSignificantStatements>
<breaksConcat>oracle.dbtools.app.Format.Breaks.Before</breaksConcat>
<breakAfterIf>false</breakAfterIf>
<brkCtrlSeparateConditionsActions>false</brkCtrlSeparateConditionsActions>
<breakAfterElse>false</breakAfterElse>
<spaceAroundBrackets>oracle.dbtools.app.Format.Space.Default</spaceAroundBrackets>
<flowControl>oracle.dbtools.app.Format.FlowControl.Terse</flowControl>
<commasPerLine>1</commasPerLine>
<brkCtrlTerse>false</brkCtrlTerse>
<forceLinebreaksBeforeComment>false</forceLinebreaksBeforeComment>
<breakAfterWhile>false</breakAfterWhile>
<keepQuotedIdentifiers>false</keepQuotedIdentifiers>
<alignTypeDecl>true</alignTypeDecl>
<breakParenCondition>true</breakParenCondition>
<parseForwardAndBackward>true</parseForwardAndBackward>
<identSpaces>3</identSpaces>
<breakAfterCase>false</breakAfterCase>
<breakAfterThen>false</breakAfterThen>
<breaksAfterSelect>false</breaksAfterSelect>
<spaceAfterCommas>true</spaceAfterCommas>
<kwCase>oracle.dbtools.app.Format.Case.UPPER</kwCase>
</options>
PhilippSalvisberg commented 1 year ago

I cannot reproduce it. Please note that the Arbori program is reset when you import the XML file. Can you please check again? thanks.