microsoft / SqlScriptDOM

ScriptDOM/SqlDOM is a .NET library for parsing T-SQL statements and interacting with its abstract syntax tree

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add quotes for "Incorrect syntax near XXX"

Frankkkkk opened this issue · comments

Hi,
When exporting a schema from a server, there can be problem if the schema on the DB is not compliant with the tool.

For example, for the following view/table:

CREATE VIEW [40].[HelloWorld]
AS
SELECT  Something
FROM OPENROWSET(
    BULK 'myfile.csv',
    DATA_SOURCE = 'ds',
    FORMAT = 'CSV',
    FIRSTROW = 3,
    HEADER_ROW = TRUE,
    delimiter = ';',
    PARSER_VERSION = '1.0'
) 

In this case, sqlpackage will raise en error like so:

*** Error validating element [40].[HelloWorld]: Incorrect syntax near delimiter.

In this case, delimiter is not a delimiter, but the delimiter keyword in the SQL code! This was really confusing to me (and a nice coincidence too)!

Describe the solution you'd like
Just quote the element in the error message:

*** Error validating element [40].[HelloWorld]: Incorrect syntax near 'delimiter'.

Describe alternatives you've considered

Additional context

Thanks!

@Frankkkkk I transferred the issue here because it's a Scriptdom bug. I cannot find any public document for those properties of OpenrowSet. https://learn.microsoft.com/en-us/sql/t-sql/functions/openrowset-transact-sql?view=sql-server-ver16&viewFallbackFrom=azure-sqldw-latest#syntax if you have any resource about those properties would you please share with us. thanks

Hi @llali thanks for that !

Indeed, our syntax was not correct (although it worked for a strange reason?). The main "issue" was proposing to add these quotes around the invalid term. I can make a MR if that makes it easier?

cheers

Looking at the code, I'd propose quoting all terms that are shown in ambiguous error messages. Some of them already quote the terms:

Option '{0}' is not a valid index option in '{1}' statement
The same large data placement option '{0}' has been specified twice

Cheers