Skip to content

Formatter needs to allow insert columns on separate lines #189

Open

Description

@dmaloo

formatter

Is your feature request related to a problem? Please describe.
Formatter lumps all columns together for an INSERT statement on same line.

Describe the solution you'd like
Please describe the desired behavior.
Like it is with SELECT each column should be allowed its own line as an option.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Activity

  1. Benjin commented on Apr 5, 2022

    @Benjin

    Looks like a good way we can improve ScriptDom formatting! Thanks for reporting this. Out of curiosity, what DacFx operation were you performing when you found this?

  2. dmaloo commented on Apr 5, 2022

    @dmaloo
    Author

    Hi Benjin, just generate method of generator object..as below

    $generator = [Microsoft.SqlServer.TransactSql.ScriptDom.Sql150ScriptGenerator]::New();
    $generate =     [Microsoft.SqlServer.TransactSql.ScriptDom.Sql150ScriptGenerator]($generator)
    $parser = [Microsoft.SqlServer.TransactSql.ScriptDom.TSql150Parser]($true)::New();
    if($parser -eq $null){
    throw 'ScriptDOM not installed or not accessible'
    }
    $parseerrors = $null
    $TSQLfragment = $parser.Parse($stringreader,([ref]$parseerrors))
    # raise an exception if any parsing errors occur
    if($parseerrors.Count -gt 0) {
        throw "$($parseErrors.Count) parsing error(s): $(($parseErrors | ConvertTo-Json))"
    }
    $formattedoutput = ''
    $generate.GenerateScript($tsqlfragment,([ref]$formattedoutput))
    write-host $formattedoutput -BackgroundColor blue
    

    Thanks

    Mala

  3. Benjin commented on Apr 5, 2022

    @Benjin

    Gotchya; so you're using scriptdom directly, not going through a DacFx operation that's generating an Insert statement?

  4. dmaloo commented on Apr 5, 2022

    @dmaloo
    Author

    That's correct, was only using it to format some existing code and regenerate.

  5. clement911 commented on Nov 17, 2022

    @clement911

    Is there any update an this issue?

    On a similar note, we'd also like more control to be able to format the VALUES clause on multiple lines.

    Currently the entire clause is formatted on a single line.

    Example of the current formatting on a dummy query to show the issue:

    SELECT *
    FROM   (VALUES (1, '1'), (2, '2'), (3, '3'), (4, '4'), (5, '5'), (6, '6'), (7, '7'), (8, '8'), (9, '9'), (10, '10')) AS t(col1, col2);

    We'd love it if we could have a separate line for each value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions