DacFx icon indicating copy to clipboard operation
DacFx copied to clipboard

wrong parsing results for natively compiled stored procedures

Open ghost opened this issue 2 years ago • 1 comments

  • DacFx Version: Nuget latest (160.6161.0)
  • .NET: 6.0.301
  • Environment (local platform and source/target platforms): linux-x64

Steps to Reproduce:

  1. parse create statement of natively compiled stored procedure
  2. check resulting ProcedureStatementBody.StatementList.StartColumn

sample code (place in file.fsx, then run dotnet fsi --exec file.fsx): `#r "nuget: Microsoft.SqlServer.DacFx"

open System.IO open System.Collections.Generic open Microsoft.SqlServer.TransactSql.ScriptDom

let parse sql = let parser = TSql160Parser(false) use textReader = new StringReader(sql) :> TextReader let mutable errors : IList<> = Unchecked.defaultof<IList<>> let res = parser.Parse(textReader, &errors) match errors.Count with | 0 -> res | _ -> failwith $"parse error\n\n{sql}"

let visitor = { new TSqlFragmentVisitor() with override this.Visit(proc:ProcedureStatementBody) = match Option.ofObj proc.StatementList with | Some sl -> printfn $"line: {sl.StartLine} column: {sl.StartColumn}" | _ -> () }

let proc = """ CREATE PROCEDURE dbo.usp_add_kitchen @dept_id INT, @kitchen_count INT NOT NULL WITH EXECUTE AS OWNER, SCHEMABINDING, NATIVE_COMPILATION AS BEGIN ATOMIC WITH (TRANSACTION ISOLATION LEVEL = SNAPSHOT, LANGUAGE = N'us_english')

UPDATE dbo.Departments SET kitchen_count = ISNULL(kitchen_count, 0) + @kitchen_count WHERE ID = @dept_id END; """

let parsed = parse proc parsed.Accept(visitor) `

result is:

line: 5 column: 50

which points to value of first ATOMIC WITH option, "SNAPSHOT" here

expected result:

line: 5 column: 1

ghost avatar Jun 29 '22 13:06 ghost

@kisantia @dzsquared this should be labeled with the scriptdom label to help track it. And it reproduces in C# and on Windows, so it is not a F# issue by any means.

arvindshmicrosoft avatar Aug 16 '22 03:08 arvindshmicrosoft