Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .build/Signing.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<!-- Individual project (like the ancillary tools that we use during the build which do no ship) typically override these values so they can run normally during the build, without having to disbale SNV. -->
<DelaySign>true</DelaySign>
<SignAssembly>true</SignAssembly>
<!-- This SNK file is used to sign almost all DacFx binaries (SQLDOM uses a different one) -->
<LinkKeyFile>$(EnlistmentRoot)\Externals\VS12\VS10_FinalPublicKey.snk</LinkKeyFile>
<AssemblyOriginatorKeyFile>$(EnlistmentRoot)\Externals\VS12\VS10_FinalPublicKey.snk</AssemblyOriginatorKeyFile>
<ShippingScope>External</ShippingScope>
Expand Down
9 changes: 9 additions & 0 deletions SqlScriptDom/Parser/TSql/BulkInsertStringOptionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
//------------------------------------------------------------------------------


using System.Text.RegularExpressions;

namespace Microsoft.SqlServer.TransactSql.ScriptDom
{
internal class BulkInsertStringOptionsHelper : OptionsHelper<BulkInsertOptionKind>
Expand All @@ -30,5 +32,12 @@ private BulkInsertStringOptionsHelper()
}

internal static readonly BulkInsertStringOptionsHelper Instance = new BulkInsertStringOptionsHelper();

internal static string Trim(Literal option)
{
// Remove all the whitespaces (tabs, newlines as well)
//
return Regex.Replace(option.Value.ToUpperInvariant(), @"\s*", "");
}
}
}
2 changes: 1 addition & 1 deletion SqlScriptDom/Parser/TSql/CodeGenerationSupporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ internal static class CodeGenerationSupporter
internal const string Russian = "RUSSIAN";
internal const string Romanian = "ROMANIAN";
internal const string Brazilian = "BRAZILIAN";
internal const string NorwegianBokmal = "NORWEGIAN (BOKM�L)";
internal const string NorwegianBokmal = "NORWEGIAN (BOKM�L)";
internal const string Dutch = "DUTCH";
internal const string Korean = "KOREAN";
internal const string Japanese = "JAPANESE";
Expand Down
14 changes: 13 additions & 1 deletion SqlScriptDom/Parser/TSql/TSql150.g
Original file line number Diff line number Diff line change
Expand Up @@ -6127,6 +6127,7 @@ simpleBulkInsertOptionWithValue returns [LiteralBulkInsertOption vResult = Fragm
{
Literal vValue;
Identifier iValue;
StringLiteral jsonOption;
}
: tOption:Identifier EqualsSign
( vValue = integerOrNumeric
Expand All @@ -6153,7 +6154,18 @@ simpleBulkInsertOptionWithValue returns [LiteralBulkInsertOption vResult = Fragm
else if (vResult.OptionKind == BulkInsertOptionKind.DataCompression)
MatchString(vValue, CodeGenerationSupporter.Gzip);
else if (vResult.OptionKind == BulkInsertOptionKind.RowsetOptions)
MatchString(vValue, CodeGenerationSupporter.ReadOptions);
{
jsonOption = new StringLiteral { Value = BulkInsertStringOptionsHelper.Trim(vValue) };

if (TryMatch(jsonOption, CodeGenerationSupporter.ReadOptions))
{
vValue = jsonOption;
}
else
{
MatchString(vValue, CodeGenerationSupporter.ReadOptions);
}
}
vResult.Value = vValue;
}
| iValue = identifier
Expand Down
21 changes: 20 additions & 1 deletion SqlScriptDom/Parser/TSql/TSql160.g
Original file line number Diff line number Diff line change
Expand Up @@ -6152,6 +6152,7 @@ simpleBulkInsertOptionWithValue returns [LiteralBulkInsertOption vResult = Fragm
{
Literal vValue;
Identifier iValue;
StringLiteral jsonOption;
}
: tOption:Identifier EqualsSign
( vValue = integerOrNumeric
Expand All @@ -6178,7 +6179,18 @@ simpleBulkInsertOptionWithValue returns [LiteralBulkInsertOption vResult = Fragm
else if (vResult.OptionKind == BulkInsertOptionKind.DataCompression)
MatchString(vValue, CodeGenerationSupporter.Gzip);
else if (vResult.OptionKind == BulkInsertOptionKind.RowsetOptions)
MatchString(vValue, CodeGenerationSupporter.ReadOptions);
{
jsonOption = new StringLiteral { Value = BulkInsertStringOptionsHelper.Trim(vValue) };

if (TryMatch(jsonOption, CodeGenerationSupporter.ReadOptions))
{
vValue = jsonOption;
}
else
{
MatchString(vValue, CodeGenerationSupporter.ReadOptions);
}
}
vResult.Value = vValue;
}
| iValue = identifier
Expand Down Expand Up @@ -28637,6 +28649,7 @@ inlineIndexColumnDefinition returns [IndexDefinition vResult = FragmentFactory.C
Identifier vIndexIdentifier;
FileGroupOrPartitionScheme vFileGroupOrPartitionScheme;
IndexType vIndexType = null;
bool vHasColumnList = false;
BooleanExpression vExpression;
}
:
Expand Down Expand Up @@ -28685,8 +28698,14 @@ inlineIndexColumnDefinition returns [IndexDefinition vResult = FragmentFactory.C
tRParen:RightParenthesis
{
UpdateTokenInfo(vResult,tRParen);
vHasColumnList=true;
}
)?
(
{NextTokenMatches(CodeGenerationSupporter.Include)}?
tInclude:Identifier
identifierColumnList[vResult, vResult.IncludeColumns]
)?
(vExpression = filterClause [
vIndexType == null ?
false :
Expand Down
25 changes: 0 additions & 25 deletions Test/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
-->
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<RunCodeAnalysis>false</RunCodeAnalysis>
<!-- DEVNOTE(MatteoT): None of the projects under this folder can be packaged into a NuPkg file -->
<IsPackable>false</IsPackable>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>

<!-- We should probably consolidate this with Source\Directory.Build.props into root -->
<PropertyGroup Label="Common properties for projects">
<!-- See https://docs.microsoft.com/visualstudio/msbuild/common-msbuild-project-properties. -->

Expand All @@ -29,11 +27,6 @@
<!-- put obj files in a mirror tree off the root to keep the src folder tree cleaner -->
<BaseIntermediateOutputPath Condition=" '$(BaseIntermediateOutputPath)' == '' ">$(EnlistmentRoot)\obj\$([MSBuild]::MakeRelative('$(EnlistmentRoot)\', $(MSBuildProjectDirectory)))</BaseIntermediateOutputPath>

<!-- By default, we build all projects for these TargetFrameworks.
We cannot target netcore (e.g. net5.0/net6.0) simply because
most (or all?) the .cs files have conditional compilation based on
NETSTANDARD2_1 and are not very forward-looking (maybe intentionally?)
-->
<!-- Tests currently only work for netfx -->
<TargetFrameworks>$(NetfxVersion)</TargetFrameworks>

Expand All @@ -42,26 +35,13 @@
<TargetGroup Condition="'$(TargetFramework)'=='netcoreapp3.1' Or '$(TargetFramework)'=='net5.0' Or '$(TargetFramework)'=='net6.0'">netcore</TargetGroup>
<TargetGroup Condition="'$(TargetGroup)'==''">netfx</TargetGroup>

<!-- Nuget specific properties. See https://docs.microsoft.com/nuget/reference/msbuild-targets. -->
<!-- -->
<!-- Enable restoring projects with packages.config -->
<!-- <RestorePackagesConfig>true</RestorePackagesConfig> -->

<!-- Enable optimized NuGet restore -->
<RestoreUseStaticGraphEvaluation>true</RestoreUseStaticGraphEvaluation>

<!-- Produce deterministic assemblies, requirement for ProduceReferenceAssembly -->
<!-- <Deterministic>true</Deterministic> -->

<!-- Common runsettings for all test projects, this is generated by Test\Common\GenerateRunSettings -->
<RunSettingsFilePath>$(OutputPath)\$(TargetFramework)\test.runsettings</RunSettingsFilePath>
</PropertyGroup>

<!-- The default PDB type is now "portable" which is fine for most uses. However, we may need full PDBs in a few cases:
1. For SSMS and SQL engine builds which are indexed and need to be debuggable by pre-vs2019 (this could be less of a concern going forward)
2. Debug net462 builds which are used for code coverage (currently code coverage is not wired up)
3. SDL tools like BinSkim (to be confirmed)
-->
<PropertyGroup Condition="'$(Configuration)|$(TargetGroup)' == 'Release|netfx'">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
Expand All @@ -71,9 +51,4 @@
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<!-- Don't enable localization in tests -->
<PropertyGroup>
<EnableLocalization>false</EnableLocalization>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ FROM OPENROWSET (BULK 'f1', FORMAT = 'CSV', FIELDTERMINATOR = 'aa', ROWTERMINATO

SELECT *
FROM OPENROWSET (BULK 'f1', FORMAT = 'CSV') WITH ([region] VARCHAR (100) 1, [continent] VARCHAR (100) COLLATE latin1_general_bin2 2, [products] VARCHAR (100) 3, [status] INT 4) AS a;

SELECT *
FROM OPENROWSET (BULK 'f1', FORMAT = 'CSV', FIELDTERMINATOR = 'aa', ROWTERMINATOR = 'bb', ESCAPECHAR = 'd', FIRSTROW = 1, FIELDQUOTE = 'e', DATA_COMPRESSION = 'gzip', PARSER_VERSION = '1.0', HEADER_ROW = TRUE, DATAFILETYPE = 'widechar', CODEPAGE = 'ACP', ROWSET_OPTIONS = '{"READ_OPTIONS":["ALLOW_INCONSISTENT_READS"]}') WITH ([region] VARCHAR (100)) AS a;

SELECT *
FROM OPENROWSET (BULK 'f2', FORMAT = 'CSV', FIELDTERMINATOR = 'x', ROWTERMINATOR = 'y', ESCAPECHAR = 'z', FIRSTROW = 1, FIELDQUOTE = 'e', DATA_COMPRESSION = 'gzip', PARSER_VERSION = '2.0', HEADER_ROW = TRUE, DATAFILETYPE = 'widechar', CODEPAGE = 'ACP', ROWSET_OPTIONS = '{"READ_OPTIONS":["ALLOW_INCONSISTENT_READS"]}') WITH ([region] VARCHAR (100)) AS a;
17 changes: 17 additions & 0 deletions Test/SqlDom/Baselines160/InlineIndexColumnWithINCLUDEtest.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CREATE TABLE mytable (
id BIGINT IDENTITY (1, 1) PRIMARY KEY,
col2 VARBINARY (64) NOT NULL,
col1 NVARCHAR (256) NOT NULL INDEX ix__mytable__col1__col2 NONCLUSTERED (col1) INCLUDE (col2)
);

CREATE TABLE mytable (
id BIGINT IDENTITY (1, 1) PRIMARY KEY,
col2 VARBINARY (64) NOT NULL,
col1 NVARCHAR (256) NOT NULL INDEX ix__mytable__col1__col2 NONCLUSTERED (col1)
);

CREATE TABLE mytable (
id BIGINT IDENTITY (1, 1) PRIMARY KEY,
col2 VARBINARY (64) NOT NULL,
col1 NVARCHAR (256) NOT NULL INDEX ix__mytable__col1__col2 NONCLUSTERED (col1) INCLUDE (col2, id)
);
2 changes: 1 addition & 1 deletion Test/SqlDom/Only150SyntaxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public partial class SqlDomTests
new ParserTest150("ScalarUDFInlineTests150.sql", 4, 5, 5, 5, 5, 4, 4),
new ParserTest150("GraphDbSyntaxTests150.sql", 5, 5, 5, 5, 5, 5, 5),
new ParserTest150("BulkInsertStatementTests150.sql", 6, 6, 6, 6, 6, 6, 6),
new ParserTest150("OpenRowsetBulkStatementTests150.sql", 10, 10, 10, 10, 10, 10, 10),
new ParserTest150("OpenRowsetBulkStatementTests150.sql", 12, 12, 12, 12, 12, 12, 12),
/* When a batch is being parsed via a rule and the rule consumes all the tokens it can then it expects
the batch to end with a GO. If there is not a 'GO' then the parser assumes that we have reached EOF.
This is the current parser behavior. So any new addition to the end of the rule will result in parsing errors
Expand Down
3 changes: 2 additions & 1 deletion Test/SqlDom/Only160SyntaxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public partial class SqlDomTests
new ParserTest160(scriptFilename: "OpenRowsetBulkStatementTests160.sql", nErrors80: 8, nErrors90: 8, nErrors100: 8, nErrors110: 8, nErrors120: 8, nErrors130: 8, nErrors140: 8, nErrors150: 8),
new ParserTest160(scriptFilename: "CreateStatisticsStatementTests160.sql", nErrors80: 4, nErrors90: 4, nErrors100: 4, nErrors110: 4, nErrors120: 4, nErrors130: 4, nErrors140: 4, nErrors150: 4),
new ParserTest160(scriptFilename: "CreateExternalFileFormatStatementTests160.sql", nErrors80: 2, nErrors90: 2, nErrors100: 2, nErrors110: 2, nErrors120: 2, nErrors130: 1, nErrors140: 1, nErrors150: 1),
new ParserTest160("StringConcatOperatorTests160.sql", nErrors80: 11, nErrors90: 11, nErrors100: 11, nErrors110: 11, nErrors120: 11, nErrors130: 11, nErrors140: 11, nErrors150: 11)
new ParserTest160("StringConcatOperatorTests160.sql", nErrors80: 11, nErrors90: 11, nErrors100: 11, nErrors110: 11, nErrors120: 11, nErrors130: 11, nErrors140: 11, nErrors150: 11),
new ParserTest160("InlineIndexColumnWithINCLUDEtest.sql", nErrors80: 3, nErrors90: 3, nErrors100: 3, nErrors110: 3, nErrors120: 2, nErrors130: 2, nErrors140: 2, nErrors150: 2)
};

private static readonly ParserTest[] SqlAzure160_TestInfos =
Expand Down
3 changes: 3 additions & 0 deletions Test/SqlDom/ParserErrorsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5809,6 +5809,9 @@ public void OpenrowsetSynapseSqlServerlessOptionsNegativeTest()
ParserTestUtils.ErrorTest150("SELECT * FROM OPENROWSET (BULK 'f1', FORMAT = 'CSV') WITH ([region] COLLATE Latin1_General_BIN2) AS a;", new ParserErrorInfo(68, "SQL46010", "COLLATE"));
ParserTestUtils.ErrorTest150("SELECT * FROM OPENROWSET (BULK 'f1', FORMAT = 'PARQUET', PARSER_VERSION = '1.0') AS a;", new ParserErrorInfo(31, "SQL46142"));
ParserTestUtils.ErrorTest150("SELECT * FROM OPENROWSET (BULK 'f1', FORMAT = 'PARQUET', ROWSET_OPTIONS = '{\"READ_OPTIONS\":[\"ALLOW_INCONSISTENT_READS\"]}')) AS a;", new ParserErrorInfo(31, "SQL46142"));
ParserTestUtils.ErrorTest150("SELECT * FROM OPENROWSET (BULK 'f1', FORMAT = 'PARQUET', ROWSET_OPTIONS = '')) AS a;", new ParserErrorInfo(74, "SQL46010", "''"));
ParserTestUtils.ErrorTest150("SELECT * FROM OPENROWSET (BULK 'f1', FORMAT = 'PARQUET', ROWSET_OPTIONS = 'READ_OPTIONS = ALLOW_INCONSISTENT_READS')) AS a;", new ParserErrorInfo(74, "SQL46010", "'READ_OPTIONS = ALLOW_INCONSISTENT_READS'"));
ParserTestUtils.ErrorTest150("SELECT * FROM OPENROWSET (BULK 'f1', FORMAT = 'PARQUET', ROWSET_OPTIONS = '\"READ_OPTIONS\" : allow_INCONSISTENT_READS')) AS x;", new ParserErrorInfo(74, "SQL46010", "'\"READ_OPTIONS\" : allow_INCONSISTENT_READS'"));
}

[TestMethod]
Expand Down
16 changes: 8 additions & 8 deletions Test/SqlDom/TSqlParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -481,14 +481,14 @@ public void FieldQuoteParsingIn160ParserTest()
{
TSql160Parser parser = new TSql160Parser(true); IList<ParseError> errors;

string scriptString = @"create PROC [dbo].[test]� AS
����������������������������������� BEGIN
����������������������������������� CREATE TABLE #Test
����������������������������������� ([Col1] [NVARCHAR](266));
����������������������������������� COPY INTO #Test
����������������������������������� FROM 'https://xxxx.blob.core.windows.net/raw/'
����������������������������������� WITH (FIELDQUOTE='',FIRSTROW = 1)
����������������������������������� END;";
string scriptString = @"create PROC [dbo].[test]� AS
����������������������������������� BEGIN
����������������������������������� CREATE TABLE #Test
����������������������������������� ([Col1] [NVARCHAR](266));
����������������������������������� COPY INTO #Test
����������������������������������� FROM 'https://xxxx.blob.core.windows.net/raw/'
����������������������������������� WITH (FIELDQUOTE='',FIRSTROW = 1)
����������������������������������� END;";

var script = new StringReader(scriptString);
parser.Parse(script, out errors);
Expand Down
17 changes: 17 additions & 0 deletions Test/SqlDom/TestScripts/InlineIndexColumnWithINCLUDEtest.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CREATE TABLE mytable (
id BIGINT IDENTITY (1, 1) PRIMARY KEY,
col2 VARBINARY (64) NOT NULL,
col1 NVARCHAR (256) NOT NULL INDEX ix__mytable__col1__col2 NONCLUSTERED (col1) INCLUDE (col2)
);

CREATE TABLE mytable (
id BIGINT IDENTITY (1, 1) PRIMARY KEY,
col2 VARBINARY (64) NOT NULL,
col1 NVARCHAR (256) NOT NULL INDEX ix__mytable__col1__col2 NONCLUSTERED (col1)
);

CREATE TABLE mytable (
id BIGINT IDENTITY (1, 1) PRIMARY KEY,
col2 VARBINARY (64) NOT NULL,
col1 NVARCHAR (256) NOT NULL INDEX ix__mytable__col1__col2 NONCLUSTERED (col1) INCLUDE (col2, id)
);
19 changes: 17 additions & 2 deletions Test/SqlDom/TestScripts/OpenRowsetBulkStatementTests150.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,20 @@ select * from openrowset (bulk 'f1', escapechar = '\\', format = 'csV', formatfi
select * from openrowset (bulk 'f1', format = 'PARQUET') as a;
select * from openrowset (bulk 'f1', format = 'DELTA') as a;
select * from openrowset (bulk 'f1', format = 'PARQUET', fieldterminator = 'aa', rowterminator = 'bb', escapechar = 'd', firstrow = 1, fieldquote = 'e', data_compression = 'gzip', header_row = TRUE, datafiletype = 'widechar', codepage = 'ACP') as a;
select * from openrowset (bulk 'f1', format = 'CSV', fieldterminator = 'aa', rowterminator = 'bb', escapechar = 'd', firstrow = 1, fieldquote = 'e', data_compression = 'gzip', parser_version = '1.0', header_row = TRUE, datafiletype = 'widechar', codepage = 'ACP', rowset_options = '{"READ_OPTIONS":["ALLOW_INCONSISTENT_READS"]}') with ([region] varchar(100)) as a;
select * from openrowset (bulk 'f1', format = 'CSV') with ([region] varchar(100) 1, [continent] varchar(100) collate latin1_general_bin2 2, [products] varchar(100) 3, [status] int 4) as a;
select * from openrowset (bulk 'f1', format = 'CSV', fieldterminator = 'aa', rowterminator = 'bb', escapechar = 'd', firstrow = 1, fieldquote = 'e', data_compression = 'gzip', parser_version = '1.0', header_row = TRUE, datafiletype = 'widechar', codepage = 'ACP', rowset_options = '{ "READ_OPTIONS" :["ALLOW_INCONSISTENT_READS" ] } ') with ([region] varchar(100)) as a;
select * from openrowset (bulk 'f1', format = 'CSV') with ([region] varchar(100) 1, [continent] varchar(100) collate latin1_general_bin2 2, [products] varchar(100) 3, [status] int 4) as a;
select * from openrowset (bulk 'f1', format = 'CSV', fieldterminator = 'aa', rowterminator = 'bb', escapechar = 'd', firstrow = 1, fieldquote = 'e', data_compression = 'gzip', parser_version = '1.0', header_row = TRUE, datafiletype = 'widechar', codepage = 'ACP', rowset_options = '
{
"READ_OPTIONS"
:
[ "ALLOW_INCONSISTENT_READS"]

}
') with ([region] varchar(100)) as a;
select * from openrowset (bulk 'f2', format = 'CSV', fieldterminator = 'x', rowterminator = 'y', escapechar = 'z', firstrow = 1, fieldquote = 'e', data_compression = 'gzip', parser_version = '2.0', header_row = TRUE, datafiletype = 'widechar', codepage = 'ACP', rowset_options = '
{
"read_options":
[ "ALLOW_INCONSISTENT_reads" ]

}
') with ([region] varchar(100)) as a;
3 changes: 0 additions & 3 deletions tools/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
-->
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>

<!-- Don't enable localization for ancillary tools only needed during the build -->
<EnableLocalization>False</EnableLocalization>

<!-- Don't generate XML DOC for ancillary tools only needed during the build -->
<GenerateDocumentationFile>False</GenerateDocumentationFile>

Expand Down