microsoft / SqlScriptDOM

ScriptDOM/SqlDOM is a .NET library for parsing T-SQL statements and interacting with its abstract syntax tree
MIT License
127 stars 13 forks source link

Schema differences for scalar-valued function #85

Open hgsenger opened 3 months ago

hgsenger commented 3 months ago

Steps to Reproduce: -- SSMS>

USE MASTER; GO

CREATE DATABASE dacFxRepro; GO

USE dacFxRepro; GO

SET ANSI_NULLS ON GO

SET QUOTED_IDENTIFIER ON GO

CREATE FUNCTION [dbo].[UETrim] (@text NVARCHAR(MAX)) RETURNS NVARCHAR(MAX) WITH SCHEMABINDING AS BEGIN RETURN (TRIM(NCHAR(0x09) + NCHAR(0x20) + NCHAR(0x0D) + NCHAR(0x0A) FROM @text)) END GO

-- PS> -- dotnet tool install --global microsoft.sqlpackage --ignore-failed-sources -- $server = '.' -- $database = 'dacFxRepro' -- $connectionString = "server=$server;database=$database;Integrated Security=true;Connection Timeout=300;Trusted_Connection=True;Encrypt=False;Command Timeout=300" -- $dacpacPath = '.\dacFxRepro.dacpac' -- sqlpackage @('/Action:Extract', "/TargetFile:$dacpacPath", "/SourceConnectionString:$connectionString", "/p:IgnoreUserLoginMappings=true")

-- Output: -- Connecting to database 'dacFxRepro' on server '.'. -- Extracting schema -- Extracting schema from database -- *** Error validating element [dbo].[UETrim]: Incorrect syntax near TRIM. -- Resolving references in schema model -- Validating schema model for data package -- Validating schema -- Successfully extracted database and saved it to file '...\dacFxRepro.dacpac'.

When trying to compare the dacpac-file to a database using library Microsoft.SqlServer.DacFx, schema differences of function UETrim are reported, although the functions are identical in the database and in the dacpac file.

Same with sqlpackage: -- PS> -- $outputPath = 'report.xml' -- sqlpackage @('/Action:DeployReport ', "/SourceFile:$dacpacPath", "/TargetConnectionString:$connectionString", "/OutputPath:$outputPath")

-- Output --<?xml version="1.0" encoding="utf-8"?> -- -- -- -- -- <Item Value="[dbo].[UETrim]" -- Type="SqlScalarFunction"/> -- -- -- <Item Value="[dbo].[UETrim]" -- Type="SqlScalarFunction"/> -- -- --

Did this occur in prior versions? If not - which version(s) did it work in? Yes.

(DacFx/SqlPackage/SSMS/Azure Data Studio)

dzsquared commented 1 month ago

moving this item over to scriptdom since its throwing the error on parsing the function at the root of this