DacFx
DacFx copied to clipboard
Formatter needs to allow insert columns on separate lines
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.
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?
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
Gotchya; so you're using scriptdom directly, not going through a DacFx operation that's generating an Insert statement?
That's correct, was only using it to format some existing code and regenerate.
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.