Skip to content

Commit 7ffc71e

Browse files
Fix gaps / inconsistencies in BACKUP / RESTORE device type (microsoft#40)
* Fix gaps / inconsistencies in BACKUP / RESTORE device type Originally created just to fix microsoft#29, but in the process fixed subtle issues with VirtualDevice and DatabaseSnapshot device types as well. * Add the URL device type for use with BACKUP and RESTORE statements for 110 parser and above. URL backups were introduced with SQL Server 2012. Also updated the ScriptGenerator to ensure URL devices are correctly scripted. * Add version constraints for device types DatabaseSnapshot and VirtualDevice, both of which are only supported for SQL 2005+. * Remove dead code related to Disk device type in grammar 90 and above. In all grammars other than 80, the different device types are handled by the DeviceTypesHelper class, so the special case in the grammar for Disk device type was never used. In 80 grammar though, the Disk device type is not treated as an indentifier and hence the special case for Disk is still needed. * Add regression tests for device types URL, VIRTUAL_DEVICE and DATABASE_SNAPSHOT and for good measure, DISK as well. * Address code review comments
1 parent aa1dd2b commit 7ffc71e

13 files changed

Lines changed: 175 additions & 44 deletions

File tree

SqlScriptDom/Parser/TSql/DeviceType.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public enum DeviceType
1818
Disk = 1,
1919
Tape = 2,
2020
VirtualDevice = 3,
21-
DatabaseSnapshot = 4
21+
DatabaseSnapshot = 4,
22+
Url = 5
2223
}
2324

2425
#pragma warning restore 1591

SqlScriptDom/Parser/TSql/DeviceTypesHelper.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ private DeviceTypesHelper()
1414
{
1515
AddOptionMapping(DeviceType.Disk, CodeGenerationSupporter.Disk);
1616
AddOptionMapping(DeviceType.Tape, CodeGenerationSupporter.Tape);
17-
AddOptionMapping(DeviceType.VirtualDevice, CodeGenerationSupporter.VirtualDevice);
18-
AddOptionMapping(DeviceType.DatabaseSnapshot, CodeGenerationSupporter.DatabaseSnapshot);
17+
AddOptionMapping(DeviceType.VirtualDevice, CodeGenerationSupporter.VirtualDevice, SqlVersionFlags.TSql90AndAbove);
18+
AddOptionMapping(DeviceType.DatabaseSnapshot, CodeGenerationSupporter.DatabaseSnapshot, SqlVersionFlags.TSql90AndAbove);
19+
AddOptionMapping(DeviceType.Url, CodeGenerationSupporter.Url, SqlVersionFlags.TSql110AndAbove);
1920
}
2021

2122
internal static readonly DeviceTypesHelper Instance = new DeviceTypesHelper();

SqlScriptDom/Parser/TSql/TSql100.g

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3149,11 +3149,7 @@ deviceInfo returns [DeviceInfo vResult = FragmentFactory.CreateFragment<DeviceIn
31493149
(
31503150
tDevType:Identifier
31513151
{
3152-
vResult.DeviceType = DeviceTypesHelper.Instance.ParseOption(tDevType);
3153-
}
3154-
| Disk
3155-
{
3156-
vResult.DeviceType = DeviceType.Disk;
3152+
vResult.DeviceType = DeviceTypesHelper.Instance.ParseOption(tDevType, SqlVersionFlags.TSql100);
31573153
}
31583154
)
31593155
EqualsSign vPhysicalDevice = stringOrVariable

SqlScriptDom/Parser/TSql/TSql110.g

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3855,11 +3855,7 @@ deviceInfo returns [DeviceInfo vResult = FragmentFactory.CreateFragment<DeviceIn
38553855
(
38563856
tDevType:Identifier
38573857
{
3858-
vResult.DeviceType = DeviceTypesHelper.Instance.ParseOption(tDevType);
3859-
}
3860-
| Disk
3861-
{
3862-
vResult.DeviceType = DeviceType.Disk;
3858+
vResult.DeviceType = DeviceTypesHelper.Instance.ParseOption(tDevType, SqlVersionFlags.TSql110);
38633859
}
38643860
)
38653861
EqualsSign vPhysicalDevice = stringOrVariable

SqlScriptDom/Parser/TSql/TSql120.g

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3965,11 +3965,7 @@ deviceInfo returns [DeviceInfo vResult = FragmentFactory.CreateFragment<DeviceIn
39653965
(
39663966
tDevType:Identifier
39673967
{
3968-
vResult.DeviceType = DeviceTypesHelper.Instance.ParseOption(tDevType);
3969-
}
3970-
| Disk
3971-
{
3972-
vResult.DeviceType = DeviceType.Disk;
3968+
vResult.DeviceType = DeviceTypesHelper.Instance.ParseOption(tDevType, SqlVersionFlags.TSql120);
39733969
}
39743970
)
39753971
EqualsSign vPhysicalDevice = stringOrVariable

SqlScriptDom/Parser/TSql/TSql130.g

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4833,11 +4833,7 @@ deviceInfo returns [DeviceInfo vResult = FragmentFactory.CreateFragment<DeviceIn
48334833
(
48344834
tDevType:Identifier
48354835
{
4836-
vResult.DeviceType = DeviceTypesHelper.Instance.ParseOption(tDevType);
4837-
}
4838-
| Disk
4839-
{
4840-
vResult.DeviceType = DeviceType.Disk;
4836+
vResult.DeviceType = DeviceTypesHelper.Instance.ParseOption(tDevType, SqlVersionFlags.TSql130);
48414837
}
48424838
)
48434839
EqualsSign vPhysicalDevice = stringOrVariable

SqlScriptDom/Parser/TSql/TSql140.g

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5189,11 +5189,7 @@ deviceInfo returns [DeviceInfo vResult = FragmentFactory.CreateFragment<DeviceIn
51895189
(
51905190
tDevType:Identifier
51915191
{
5192-
vResult.DeviceType = DeviceTypesHelper.Instance.ParseOption(tDevType);
5193-
}
5194-
| Disk
5195-
{
5196-
vResult.DeviceType = DeviceType.Disk;
5192+
vResult.DeviceType = DeviceTypesHelper.Instance.ParseOption(tDevType, SqlVersionFlags.TSql140);
51975193
}
51985194
)
51995195
EqualsSign vPhysicalDevice = stringOrVariable

SqlScriptDom/Parser/TSql/TSql150.g

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5712,11 +5712,7 @@ deviceInfo returns [DeviceInfo vResult = FragmentFactory.CreateFragment<DeviceIn
57125712
(
57135713
tDevType:Identifier
57145714
{
5715-
vResult.DeviceType = DeviceTypesHelper.Instance.ParseOption(tDevType);
5716-
}
5717-
| Disk
5718-
{
5719-
vResult.DeviceType = DeviceType.Disk;
5715+
vResult.DeviceType = DeviceTypesHelper.Instance.ParseOption(tDevType, SqlVersionFlags.TSql150);
57205716
}
57215717
)
57225718
EqualsSign vPhysicalDevice = stringOrVariable

SqlScriptDom/Parser/TSql/TSql160.g

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5737,11 +5737,7 @@ deviceInfo returns [DeviceInfo vResult = FragmentFactory.CreateFragment<DeviceIn
57375737
(
57385738
tDevType:Identifier
57395739
{
5740-
vResult.DeviceType = DeviceTypesHelper.Instance.ParseOption(tDevType);
5741-
}
5742-
| Disk
5743-
{
5744-
vResult.DeviceType = DeviceType.Disk;
5740+
vResult.DeviceType = DeviceTypesHelper.Instance.ParseOption(tDevType, SqlVersionFlags.TSql160);
57455741
}
57465742
)
57475743
EqualsSign vPhysicalDevice = stringOrVariable

SqlScriptDom/Parser/TSql/TSql80.g

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ deviceInfo returns [DeviceInfo vResult = FragmentFactory.CreateFragment<DeviceIn
12591259
(
12601260
tDevType:Identifier
12611261
{
1262-
vResult.DeviceType = DeviceTypesHelper.Instance.ParseOption(tDevType);
1262+
vResult.DeviceType = DeviceTypesHelper.Instance.ParseOption(tDevType, SqlVersionFlags.TSql80);
12631263
}
12641264
| Disk
12651265
{

0 commit comments

Comments
 (0)