Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong parsing results for natively compiled stored procedures #31

Closed
ghost opened this issue Jun 29, 2022 · 1 comment · Fixed by #52
Closed

wrong parsing results for natively compiled stored procedures #31

ghost opened this issue Jun 29, 2022 · 1 comment · Fixed by #52
Assignees
Labels
bug Something isn't working

Comments

@ghost
Copy link
Contributor

ghost commented Jun 29, 2022

  • 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

@arvindshmicrosoft
Copy link
Member

arvindshmicrosoft commented Aug 16, 2022

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants