Modernize SqlCompiler and tuples.
Sean Hall committed
Apr 6, 2020 at 09:06 UTC
2df59141a12979c9869ad2e62d01e9f7432e2f7c
10 files changed
+220
-247
src/test/WixToolsetTest.Sql/SqlExtensionFixture.cs
+2
-2
@@ -19,8 +19,8 @@ namespace WixToolsetTest.Sql
19
var results = build.BuildAndQuery(Build, "SqlString");
20
Assert.Equal(new[]
21
{
22
- "SqlString:TestString\tTestDB\tfilF5_pLhBuF5b4N9XEo52g_hUM5Lo\tCREATE TABLE TestTable1(name varchar(20), value varchar(20))\t\t1\t0",
23
- }, results.OrderBy(s => s).ToArray());
22
+ "SqlString:TestString\tTestDB\tfilF5_pLhBuF5b4N9XEo52g_hUM5Lo\tCREATE TABLE TestTable1(name varchar(20), value varchar(20))\t\t1\t",
23
+ }, results.ToArray());
24
}
25
26
private static void Build(string[] args)
src/wixext/SqlCompiler.cs
+79
-63
@@ -7,6 +7,7 @@ namespace WixToolset.Sql
7
using System.Xml.Linq;
8
using WixToolset.Data;
9
using WixToolset.Extensibility;
10
+ using WixToolset.Sql.Tuples;
11
12
/// <summary>
13
/// The compiler for the WiX Toolset SQL Server Extension.
@@ -45,8 +46,8 @@ namespace WixToolset.Sql
46
switch (parentElement.Name.LocalName)
47
{
48
case "Component":
48
- string componentId = context["ComponentId"];
49
- string directoryId = context["DirectoryId"];
49
+ var componentId = context["ComponentId"];
50
+ var directoryId = context["DirectoryId"];
51
52
switch (element.Name.LocalName)
53
{
@@ -92,7 +93,7 @@ namespace WixToolset.Sql
93
/// <param name="componentId">Identifier for parent component.</param>
94
private void ParseSqlDatabaseElement(Intermediate intermediate, IntermediateSection section, XElement element, string componentId)
95
{
95
- SourceLineNumber sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element);
96
+ var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element);
97
Identifier id = null;
98
int attributes = 0;
99
string database = null;
@@ -102,7 +103,7 @@ namespace WixToolset.Sql
103
string server = null;
104
string user = null;
105
105
- foreach (XAttribute attrib in element.Attributes())
106
+ foreach (var attrib in element.Attributes())
107
{
108
if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace)
109
{
@@ -230,7 +231,7 @@ namespace WixToolset.Sql
231
232
if (null == id)
233
{
233
- this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Id"));
234
+ id = this.ParseHelper.CreateIdentifier("sdb", componentId, server, database);
235
}
236
237
if (null == database)
@@ -252,11 +253,11 @@ namespace WixToolset.Sql
253
this.Messaging.Write(SqlErrors.OneOfAttributesRequiredUnderComponent(sourceLineNumbers, element.Name.LocalName, "CreateOnInstall", "CreateOnUninstall", "DropOnInstall", "DropOnUninstall"));
254
}
255
255
- foreach (XElement child in element.Elements())
256
+ foreach (var child in element.Elements())
257
{
258
if (this.Namespace == child.Name.Namespace)
259
{
259
- SourceLineNumber childSourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(child);
260
+ var childSourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(child);
261
switch (child.Name.LocalName)
262
{
263
case "SqlScript":
@@ -285,7 +286,7 @@ namespace WixToolset.Sql
286
this.Messaging.Write(ErrorMessages.TooManyElements(sourceLineNumbers, element.Name.LocalName, child.Name.LocalName, 1));
287
}
288
288
- fileSpec = this.ParseSqlFileSpecElement(intermediate, section, child);
289
+ fileSpec = this.ParseSqlFileSpecElement(intermediate, section, child, id?.Id);
290
break;
291
case "SqlLogFileSpec":
292
if (null == componentId)
@@ -297,7 +298,7 @@ namespace WixToolset.Sql
298
this.Messaging.Write(ErrorMessages.TooManyElements(sourceLineNumbers, element.Name.LocalName, child.Name.LocalName, 1));
299
}
300
300
- logFileSpec = this.ParseSqlFileSpecElement(intermediate, section, child);
301
+ logFileSpec = this.ParseSqlFileSpecElement(intermediate, section, child, id?.Id);
302
break;
303
default:
304
this.ParseHelper.UnexpectedElement(element, child);
@@ -313,23 +314,25 @@ namespace WixToolset.Sql
314
if (null != componentId)
315
{
316
// Reference InstallSqlData and UninstallSqlData since nothing will happen without it
316
- this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", "InstallSqlData");
317
- this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", "UninstallSqlData");
317
+ this.AddReferenceToInstallSqlData(section, sourceLineNumbers);
318
}
319
320
if (!this.Messaging.EncounteredError)
321
{
322
- var row = this.ParseHelper.CreateRow(section, sourceLineNumbers, "SqlDatabase", id);
323
- row.Set(1, server);
324
- row.Set(2, instance);
325
- row.Set(3, database);
326
- row.Set(4, componentId);
327
- row.Set(5, user);
328
- row.Set(6, fileSpec?.Id);
329
- row.Set(7, logFileSpec?.Id);
322
+ var tuple = section.AddTuple(new SqlDatabaseTuple(sourceLineNumbers, id)
323
+ {
324
+ Server = server,
325
+ Instance = instance,
326
+ Database = database,
327
+ ComponentRef = componentId,
328
+ UserRef = user,
329
+ FileSpecRef = fileSpec?.Id,
330
+ LogFileSpecRef = logFileSpec?.Id,
331
+ });
332
+
333
if (0 != attributes)
334
{
332
- row.Set(8, attributes);
335
+ tuple.Attributes = attributes;
336
}
337
}
338
}
@@ -341,9 +344,9 @@ namespace WixToolset.Sql
344
/// <param name="section"></param>
345
/// <param name="element">Element to parse.</param>
346
/// <returns>Identifier of sql file specification.</returns>
344
- private Identifier ParseSqlFileSpecElement(Intermediate intermediate, IntermediateSection section, XElement element)
347
+ private Identifier ParseSqlFileSpecElement(Intermediate intermediate, IntermediateSection section, XElement element, string parentId)
348
{
346
- SourceLineNumber sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element);
349
+ var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element);
350
Identifier id = null;
351
string fileName = null;
352
string growthSize = null;
@@ -351,7 +354,7 @@ namespace WixToolset.Sql
354
string name = null;
355
string size = null;
356
354
- foreach (XAttribute attrib in element.Attributes())
357
+ foreach (var attrib in element.Attributes())
358
{
359
if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace)
360
{
@@ -388,7 +391,7 @@ namespace WixToolset.Sql
391
392
if (null == id)
393
{
391
- this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Id"));
394
+ id = this.ParseHelper.CreateIdentifier("sfs", parentId, name, fileName);
395
}
396
397
if (null == name)
@@ -405,22 +408,25 @@ namespace WixToolset.Sql
408
409
if (!this.Messaging.EncounteredError)
410
{
408
- var row = this.ParseHelper.CreateRow(section, sourceLineNumbers, "SqlFileSpec", id);
409
- row.Set(1, name);
410
- row.Set(2, fileName);
411
+ var tuple = section.AddTuple(new SqlFileSpecTuple(sourceLineNumbers, id)
412
+ {
413
+ Name = name,
414
+ Filename = fileName,
415
+ });
416
+
417
if (null != size)
418
{
413
- row.Set(3, size);
419
+ tuple.Size = size;
420
}
421
422
if (null != maxSize)
423
{
418
- row.Set(4, maxSize);
424
+ tuple.MaxSize = maxSize;
425
}
426
427
if (null != growthSize)
428
{
423
- row.Set(5, growthSize);
429
+ tuple.GrowthSize = growthSize;
430
}
431
}
432
@@ -435,16 +441,16 @@ namespace WixToolset.Sql
441
/// <param name="sqlDb">Optional database to execute script against.</param>
442
private void ParseSqlScriptElement(Intermediate intermediate, IntermediateSection section, XElement element, string componentId, string sqlDb)
443
{
438
- SourceLineNumber sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element);
444
+ var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element);
445
Identifier id = null;
446
int attributes = 0;
441
- bool rollbackAttribute = false;
442
- bool nonRollbackAttribute = false;
447
+ var rollbackAttribute = false;
448
+ var nonRollbackAttribute = false;
449
string binary = null;
444
- int sequence = CompilerConstants.IntegerNotSet;
450
+ var sequence = CompilerConstants.IntegerNotSet;
451
string user = null;
452
447
- foreach (XAttribute attrib in element.Attributes())
453
+ foreach (var attrib in element.Attributes())
454
{
455
if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace)
456
{
@@ -455,7 +461,7 @@ namespace WixToolset.Sql
461
break;
462
case "BinaryKey":
463
binary = this.ParseHelper.GetAttributeIdentifierValue(sourceLineNumbers, attrib);
458
- this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "Binary", binary);
464
+ this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, TupleDefinitions.Binary, binary);
465
break;
466
case "Sequence":
467
sequence = this.ParseHelper.GetAttributeIntegerValue(sourceLineNumbers, attrib, 1, short.MaxValue);
@@ -466,7 +472,7 @@ namespace WixToolset.Sql
472
this.Messaging.Write(ErrorMessages.IllegalAttributeWhenNested(sourceLineNumbers, element.Name.LocalName, attrib.Name.LocalName, element.Parent.Name.LocalName));
473
}
474
sqlDb = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib);
469
- this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "SqlDatabase", sqlDb);
475
+ this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, SqlTupleDefinitions.SqlDatabase, sqlDb);
476
break;
477
case "User":
478
user = this.ParseHelper.GetAttributeIdentifierValue(sourceLineNumbers, attrib);
@@ -568,7 +574,7 @@ namespace WixToolset.Sql
574
575
if (null == id)
576
{
571
- this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Id"));
577
+ id = this.ParseHelper.CreateIdentifier("ssc", componentId, binary, sqlDb);
578
}
579
580
if (null == binary)
@@ -589,20 +595,22 @@ namespace WixToolset.Sql
595
this.ParseHelper.ParseForExtensionElements(this.Context.Extensions, intermediate, section, element);
596
597
// Reference InstallSqlData and UninstallSqlData since nothing will happen without it
592
- this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", "InstallSqlData");
593
- this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", "UninstallSqlData");
598
+ this.AddReferenceToInstallSqlData(section, sourceLineNumbers);
599
600
if (!this.Messaging.EncounteredError)
601
{
597
- var row = this.ParseHelper.CreateRow(section, sourceLineNumbers, "SqlScript", id);
598
- row.Set(1, sqlDb);
599
- row.Set(2, componentId);
600
- row.Set(3, binary);
601
- row.Set(4, user);
602
- row.Set(5, attributes);
602
+ var tuple = section.AddTuple(new SqlScriptTuple(sourceLineNumbers, id)
603
+ {
604
+ SqlDbRef = sqlDb,
605
+ ComponentRef = componentId,
606
+ ScriptBinaryRef = binary,
607
+ UserRef = user,
608
+ Attributes = attributes,
609
+ });
610
+
611
if (CompilerConstants.IntegerNotSet != sequence)
612
{
605
- row.Set(6, sequence);
613
+ tuple.Sequence = sequence;
614
}
615
}
616
}
@@ -615,16 +623,16 @@ namespace WixToolset.Sql
623
/// <param name="sqlDb">Optional database to execute string against.</param>
624
private void ParseSqlStringElement(Intermediate intermediate, IntermediateSection section, XElement element, string componentId, string sqlDb)
625
{
618
- SourceLineNumber sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element);
626
+ var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element);
627
Identifier id = null;
628
int attributes = 0;
621
- bool rollbackAttribute = false;
622
- bool nonRollbackAttribute = false;
623
- int sequence = CompilerConstants.IntegerNotSet;
629
+ var rollbackAttribute = false;
630
+ var nonRollbackAttribute = false;
631
+ var sequence = CompilerConstants.IntegerNotSet;
632
string sql = null;
633
string user = null;
634
627
- foreach (XAttribute attrib in element.Attributes())
635
+ foreach (var attrib in element.Attributes())
636
{
637
if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace)
638
{
@@ -727,7 +735,7 @@ namespace WixToolset.Sql
735
}
736
737
sqlDb = this.ParseHelper.GetAttributeIdentifierValue(sourceLineNumbers, attrib);
730
- this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "SqlDatabase", sqlDb);
738
+ this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, SqlTupleDefinitions.SqlDatabase, sqlDb);
739
break;
740
case "User":
741
user = this.ParseHelper.GetAttributeIdentifierValue(sourceLineNumbers, attrib);
@@ -746,7 +754,7 @@ namespace WixToolset.Sql
754
755
if (null == id)
756
{
749
- this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Id"));
757
+ id = this.ParseHelper.CreateIdentifier("sst", componentId, sql, sqlDb);
758
}
759
760
if (null == sql)
@@ -767,22 +775,30 @@ namespace WixToolset.Sql
775
this.ParseHelper.ParseForExtensionElements(this.Context.Extensions, intermediate, section, element);
776
777
// Reference InstallSqlData and UninstallSqlData since nothing will happen without it
770
- this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", "InstallSqlData");
771
- this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", "UninstallSqlData");
778
+ this.AddReferenceToInstallSqlData(section, sourceLineNumbers);
779
780
if (!this.Messaging.EncounteredError)
781
{
775
- var row = this.ParseHelper.CreateRow(section, sourceLineNumbers, "SqlString", id);
776
- row.Set(1, sqlDb);
777
- row.Set(2, componentId);
778
- row.Set(3, sql);
779
- row.Set(4, user);
780
- row.Set(5, attributes);
782
+ var tuple = section.AddTuple(new SqlStringTuple(sourceLineNumbers, id)
783
+ {
784
+ SqlDbRef = sqlDb,
785
+ ComponentRef = componentId,
786
+ SQL = sql,
787
+ UserRef = user,
788
+ Attributes = attributes,
789
+ });
790
+
791
if (CompilerConstants.IntegerNotSet != sequence)
792
{
783
- row.Set(6, sequence);
793
+ tuple.Sequence = sequence;
794
}
795
}
796
}
797
+
798
+ private void AddReferenceToInstallSqlData(IntermediateSection section, SourceLineNumber sourceLineNumbers)
799
+ {
800
+ this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, TupleDefinitions.CustomAction, "InstallSqlData");
801
+ this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, TupleDefinitions.CustomAction, "UninstallSqlData");
802
+ }
803
}
804
}
src/wixext/SqlTableDefinitions.cs
new
+82
@@ -0,0 +1,82 @@
1
+// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
+
3
+namespace WixToolset.Sql
4
+{
5
+ using WixToolset.Data.WindowsInstaller;
6
+
7
+ public static class SqlTableDefinitions
8
+ {
9
+ public static readonly TableDefinition SqlDatabase = new TableDefinition(
10
+ "SqlDatabase",
11
+ new[]
12
+ {
13
+ new ColumnDefinition("SqlDb", ColumnType.String, 72, primaryKey: true, nullable: false, ColumnCategory.Identifier, description: "Primary key, non-localized token", modularizeType: ColumnModularizeType.Column),
14
+ new ColumnDefinition("Server", ColumnType.String, 255, primaryKey: false, nullable: true, ColumnCategory.Formatted, description: "Primary key, name of server running SQL Server"),
15
+ new ColumnDefinition("Instance", ColumnType.String, 255, primaryKey: false, nullable: true, ColumnCategory.Formatted, description: "Primary key, name of SQL Server instance"),
16
+ new ColumnDefinition("Database", ColumnType.String, 255, primaryKey: false, nullable: false, ColumnCategory.Formatted, description: "Primary key, name of database in a SQL Server"),
17
+ new ColumnDefinition("Component_", ColumnType.String, 72, primaryKey: false, nullable: true, ColumnCategory.Identifier, keyTable: "Component", keyColumn: 1, description: "Foreign key, Component used to determine install state ", modularizeType: ColumnModularizeType.Column),
18
+ new ColumnDefinition("User_", ColumnType.String, 72, primaryKey: false, nullable: true, ColumnCategory.Identifier, keyTable: "User", keyColumn: 1, description: "Foreign key, User used to log into database", modularizeType: ColumnModularizeType.Column),
19
+ new ColumnDefinition("FileSpec_", ColumnType.String, 72, primaryKey: false, nullable: true, ColumnCategory.Identifier, keyTable: "SqlFileSpec", keyColumn: 1, description: "Foreign key referencing SqlFileSpec.", modularizeType: ColumnModularizeType.Column),
20
+ new ColumnDefinition("FileSpec_Log", ColumnType.String, 72, primaryKey: false, nullable: true, ColumnCategory.Identifier, keyTable: "SqlFileSpec", keyColumn: 1, description: "Foreign key referencing SqlFileSpec.", modularizeType: ColumnModularizeType.Column),
21
+ new ColumnDefinition("Attributes", ColumnType.Number, 2, primaryKey: false, nullable: true, ColumnCategory.Unknown, minValue: 0, maxValue: 255, description: "1 == create on install, 2 == drop on uninstall, 4 == continue on error, 8 == drop on install, 16 == create on uninstall, 32 == confirm update existing table, 64 == create on reinstall, 128 == drop on reinstall"),
22
+ },
23
+ tupleDefinitionName: "SqlDatabase",
24
+ tupleIdIsPrimaryKey: true
25
+ );
26
+
27
+ public static readonly TableDefinition SqlFileSpec = new TableDefinition(
28
+ "SqlFileSpec",
29
+ new[]
30
+ {
31
+ new ColumnDefinition("FileSpec", ColumnType.String, 72, primaryKey: true, nullable: false, ColumnCategory.Identifier, description: "Primary key, non-localized token", modularizeType: ColumnModularizeType.Column),
32
+ new ColumnDefinition("Name", ColumnType.String, 255, primaryKey: false, nullable: false, ColumnCategory.Formatted, description: "Logical name of filespec", modularizeType: ColumnModularizeType.Property),
33
+ new ColumnDefinition("Filename", ColumnType.String, 255, primaryKey: false, nullable: false, ColumnCategory.Formatted, description: "Filename to use (path must exist)", modularizeType: ColumnModularizeType.Property),
34
+ new ColumnDefinition("Size", ColumnType.String, 72, primaryKey: false, nullable: true, ColumnCategory.Formatted, description: "Initial size for file", modularizeType: ColumnModularizeType.Property),
35
+ new ColumnDefinition("MaxSize", ColumnType.String, 72, primaryKey: false, nullable: true, ColumnCategory.Formatted, description: "Maximum size for file", modularizeType: ColumnModularizeType.Property),
36
+ new ColumnDefinition("GrowthSize", ColumnType.String, 72, primaryKey: false, nullable: true, ColumnCategory.Formatted, description: "Size file should grow when necessary", modularizeType: ColumnModularizeType.Property),
37
+ },
38
+ tupleDefinitionName: "SqlFileSpec",
39
+ tupleIdIsPrimaryKey: true
40
+ );
41
+
42
+ public static readonly TableDefinition SqlScript = new TableDefinition(
43
+ "SqlScript",
44
+ new[]
45
+ {
46
+ new ColumnDefinition("Script", ColumnType.String, 72, primaryKey: true, nullable: false, ColumnCategory.Identifier, description: "Primary key, non-localized token"),
47
+ new ColumnDefinition("SqlDb_", ColumnType.String, 72, primaryKey: false, nullable: false, ColumnCategory.Identifier, keyTable: "SqlDatabase", keyColumn: 1, description: "Foreign key, SQL Server key", modularizeType: ColumnModularizeType.Column),
48
+ new ColumnDefinition("Component_", ColumnType.String, 72, primaryKey: false, nullable: false, ColumnCategory.Identifier, keyTable: "Component", keyColumn: 1, description: "Foreign key, Component used to determine install state", modularizeType: ColumnModularizeType.Column),
49
+ new ColumnDefinition("ScriptBinary_", ColumnType.String, 72, primaryKey: false, nullable: false, ColumnCategory.Identifier, keyTable: "Binary", keyColumn: 1, description: "Foreign key, Binary stream that contains SQL Script to execute", modularizeType: ColumnModularizeType.Column),
50
+ new ColumnDefinition("User_", ColumnType.String, 72, primaryKey: false, nullable: true, ColumnCategory.Identifier, keyTable: "User", keyColumn: 1, description: "Foreign key, User used to log into database", modularizeType: ColumnModularizeType.Column),
51
+ new ColumnDefinition("Attributes", ColumnType.Number, 2, primaryKey: false, nullable: false, ColumnCategory.Unknown, possibilities: "1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24;25;26;27;28;29;30;31", description: "1 == execute on install, 2 == execute on uninstall, 4 == continue on error, 8 == rollback on install, 16 == rollback on uninstall"),
52
+ new ColumnDefinition("Sequence", ColumnType.Number, 2, primaryKey: false, nullable: true, ColumnCategory.Unknown, description: "Order to execute SQL Queries in"),
53
+ },
54
+ tupleDefinitionName: "SqlScript",
55
+ tupleIdIsPrimaryKey: true
56
+ );
57
+
58
+ public static readonly TableDefinition SqlString = new TableDefinition(
59
+ "SqlString",
60
+ new[]
61
+ {
62
+ new ColumnDefinition("String", ColumnType.String, 72, primaryKey: true, nullable: false, ColumnCategory.Identifier, description: "Id for the SqlString", modularizeType: ColumnModularizeType.Column),
63
+ new ColumnDefinition("SqlDb_", ColumnType.String, 72, primaryKey: false, nullable: false, ColumnCategory.Identifier, keyTable: "SqlDatabase", keyColumn: 1, description: "Foreign key, SQL Server key", modularizeType: ColumnModularizeType.Column),
64
+ new ColumnDefinition("Component_", ColumnType.String, 72, primaryKey: false, nullable: false, ColumnCategory.Identifier, keyTable: "Component", keyColumn: 1, description: "Foreign key, Component used to determine install state", modularizeType: ColumnModularizeType.Column),
65
+ new ColumnDefinition("SQL", ColumnType.String, 0, primaryKey: false, nullable: false, ColumnCategory.Formatted, description: "SQL query to execute"),
66
+ new ColumnDefinition("User_", ColumnType.String, 72, primaryKey: false, nullable: true, ColumnCategory.Identifier, keyTable: "User", keyColumn: 1, description: "Foreign key, User used to log into database", modularizeType: ColumnModularizeType.Column),
67
+ new ColumnDefinition("Attributes", ColumnType.Number, 2, primaryKey: false, nullable: false, ColumnCategory.Unknown, possibilities: "1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24;25;26;27;28;29;30;31", description: "1 == execute on install, 2 == execute on uninstall, 4 == continue on error, 8 == rollback on install, 16 == rollback on uninstall"),
68
+ new ColumnDefinition("Sequence", ColumnType.Number, 2, primaryKey: false, nullable: true, ColumnCategory.Unknown, description: "Order to execute SQL Queries in"),
69
+ },
70
+ tupleDefinitionName: "SqlString",
71
+ tupleIdIsPrimaryKey: true
72
+ );
73
+
74
+ public static readonly TableDefinition[] All = new[]
75
+ {
76
+ SqlDatabase,
77
+ SqlFileSpec,
78
+ SqlScript,
79
+ SqlString,
80
+ };
81
+ }
82
+}
src/wixext/SqlWindowsInstallerBackendExtension.cs
+2
-21
@@ -1,32 +1,13 @@
1
-// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
1
+// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3
namespace WixToolset.Sql
4
{
5
using System.Collections.Generic;
6
- using System.Linq;
7
- using System.Xml;
6
using WixToolset.Data.WindowsInstaller;
7
using WixToolset.Extensibility;
8
9
public class SqlWindowsInstallerBackendBinderExtension : BaseWindowsInstallerBackendBinderExtension
10
{
13
- public SqlWindowsInstallerBackendBinderExtension()
14
- {
15
-
16
- }
17
-
18
- private static readonly TableDefinition[] Tables = LoadTables();
19
-
20
- public override IEnumerable<TableDefinition> TableDefinitions => Tables;
21
-
22
- private static TableDefinition[] LoadTables()
23
- {
24
- using (var resourceStream = typeof(SqlWindowsInstallerBackendBinderExtension).Assembly.GetManifestResourceStream("WixToolset.Sql.tables.xml"))
25
- using (var reader = XmlReader.Create(resourceStream))
26
- {
27
- var tables = TableDefinitionCollection.Load(reader);
28
- return tables.ToArray();
29
- }
30
- }
11
+ public override IEnumerable<TableDefinition> TableDefinitions => SqlTableDefinitions.All;
12
}
13
}
src/wixext/Tuples/SqlDatabaseTuple.cs
+20
-28
@@ -11,14 +11,13 @@ namespace WixToolset.Sql
11
SqlTupleDefinitionType.SqlDatabase.ToString(),
12
new[]
13
{
14
- new IntermediateFieldDefinition(nameof(SqlDatabaseTupleFields.SqlDb), IntermediateFieldType.String),
14
new IntermediateFieldDefinition(nameof(SqlDatabaseTupleFields.Server), IntermediateFieldType.String),
15
new IntermediateFieldDefinition(nameof(SqlDatabaseTupleFields.Instance), IntermediateFieldType.String),
16
new IntermediateFieldDefinition(nameof(SqlDatabaseTupleFields.Database), IntermediateFieldType.String),
18
- new IntermediateFieldDefinition(nameof(SqlDatabaseTupleFields.Component_), IntermediateFieldType.String),
19
- new IntermediateFieldDefinition(nameof(SqlDatabaseTupleFields.User_), IntermediateFieldType.String),
20
- new IntermediateFieldDefinition(nameof(SqlDatabaseTupleFields.FileSpec_), IntermediateFieldType.String),
21
- new IntermediateFieldDefinition(nameof(SqlDatabaseTupleFields.FileSpec_Log), IntermediateFieldType.String),
17
+ new IntermediateFieldDefinition(nameof(SqlDatabaseTupleFields.ComponentRef), IntermediateFieldType.String),
18
+ new IntermediateFieldDefinition(nameof(SqlDatabaseTupleFields.UserRef), IntermediateFieldType.String),
19
+ new IntermediateFieldDefinition(nameof(SqlDatabaseTupleFields.FileSpecRef), IntermediateFieldType.String),
20
+ new IntermediateFieldDefinition(nameof(SqlDatabaseTupleFields.LogFileSpecRef), IntermediateFieldType.String),
21
new IntermediateFieldDefinition(nameof(SqlDatabaseTupleFields.Attributes), IntermediateFieldType.Number),
22
},
23
typeof(SqlDatabaseTuple));
@@ -31,14 +30,13 @@ namespace WixToolset.Sql.Tuples
30
31
public enum SqlDatabaseTupleFields
32
{
34
- SqlDb,
33
Server,
34
Instance,
35
Database,
38
- Component_,
39
- User_,
40
- FileSpec_,
41
- FileSpec_Log,
36
+ ComponentRef,
37
+ UserRef,
38
+ FileSpecRef,
39
+ LogFileSpecRef,
40
Attributes,
41
}
42
@@ -54,12 +52,6 @@ namespace WixToolset.Sql.Tuples
52
53
public IntermediateField this[SqlDatabaseTupleFields index] => this.Fields[(int)index];
54
57
- public string SqlDb
58
- {
59
- get => this.Fields[(int)SqlDatabaseTupleFields.SqlDb].AsString();
60
- set => this.Set((int)SqlDatabaseTupleFields.SqlDb, value);
61
- }
62
-
55
public string Server
56
{
57
get => this.Fields[(int)SqlDatabaseTupleFields.Server].AsString();
@@ -78,28 +70,28 @@ namespace WixToolset.Sql.Tuples
70
set => this.Set((int)SqlDatabaseTupleFields.Database, value);
71
}
72
81
- public string Component_
73
+ public string ComponentRef
74
{
83
- get => this.Fields[(int)SqlDatabaseTupleFields.Component_].AsString();
84
- set => this.Set((int)SqlDatabaseTupleFields.Component_, value);
75
+ get => this.Fields[(int)SqlDatabaseTupleFields.ComponentRef].AsString();
76
+ set => this.Set((int)SqlDatabaseTupleFields.ComponentRef, value);
77
}
78
87
- public string User_
79
+ public string UserRef
80
{
89
- get => this.Fields[(int)SqlDatabaseTupleFields.User_].AsString();
90
- set => this.Set((int)SqlDatabaseTupleFields.User_, value);
81
+ get => this.Fields[(int)SqlDatabaseTupleFields.UserRef].AsString();
82
+ set => this.Set((int)SqlDatabaseTupleFields.UserRef, value);
83
}
84
93
- public string FileSpec_
85
+ public string FileSpecRef
86
{
95
- get => this.Fields[(int)SqlDatabaseTupleFields.FileSpec_].AsString();
96
- set => this.Set((int)SqlDatabaseTupleFields.FileSpec_, value);
87
+ get => this.Fields[(int)SqlDatabaseTupleFields.FileSpecRef].AsString();
88
+ set => this.Set((int)SqlDatabaseTupleFields.FileSpecRef, value);
89
}
90
99
- public string FileSpec_Log
91
+ public string LogFileSpecRef
92
{
101
- get => this.Fields[(int)SqlDatabaseTupleFields.FileSpec_Log].AsString();
102
- set => this.Set((int)SqlDatabaseTupleFields.FileSpec_Log, value);
93
+ get => this.Fields[(int)SqlDatabaseTupleFields.LogFileSpecRef].AsString();
94
+ set => this.Set((int)SqlDatabaseTupleFields.LogFileSpecRef, value);
95
}
96
97
public int Attributes
src/wixext/Tuples/SqlFileSpecTuple.cs
-8
@@ -11,7 +11,6 @@ namespace WixToolset.Sql
11
SqlTupleDefinitionType.SqlFileSpec.ToString(),
12
new[]
13
{
14
- new IntermediateFieldDefinition(nameof(SqlFileSpecTupleFields.FileSpec), IntermediateFieldType.String),
14
new IntermediateFieldDefinition(nameof(SqlFileSpecTupleFields.Name), IntermediateFieldType.String),
15
new IntermediateFieldDefinition(nameof(SqlFileSpecTupleFields.Filename), IntermediateFieldType.String),
16
new IntermediateFieldDefinition(nameof(SqlFileSpecTupleFields.Size), IntermediateFieldType.String),
@@ -28,7 +27,6 @@ namespace WixToolset.Sql.Tuples
27
28
public enum SqlFileSpecTupleFields
29
{
31
- FileSpec,
30
Name,
31
Filename,
32
Size,
@@ -48,12 +46,6 @@ namespace WixToolset.Sql.Tuples
46
47
public IntermediateField this[SqlFileSpecTupleFields index] => this.Fields[(int)index];
48
51
- public string FileSpec
52
- {
53
- get => this.Fields[(int)SqlFileSpecTupleFields.FileSpec].AsString();
54
- set => this.Set((int)SqlFileSpecTupleFields.FileSpec, value);
55
- }
56
-
49
public string Name
50
{
51
get => this.Fields[(int)SqlFileSpecTupleFields.Name].AsString();
src/wixext/Tuples/SqlScriptTuple.cs
+20
-28
@@ -11,11 +11,10 @@ namespace WixToolset.Sql
11
SqlTupleDefinitionType.SqlScript.ToString(),
12
new[]
13
{
14
- new IntermediateFieldDefinition(nameof(SqlScriptTupleFields.Script), IntermediateFieldType.String),
15
- new IntermediateFieldDefinition(nameof(SqlScriptTupleFields.SqlDb_), IntermediateFieldType.String),
16
- new IntermediateFieldDefinition(nameof(SqlScriptTupleFields.Component_), IntermediateFieldType.String),
17
- new IntermediateFieldDefinition(nameof(SqlScriptTupleFields.ScriptBinary_), IntermediateFieldType.String),
18
- new IntermediateFieldDefinition(nameof(SqlScriptTupleFields.User_), IntermediateFieldType.String),
14
+ new IntermediateFieldDefinition(nameof(SqlScriptTupleFields.SqlDbRef), IntermediateFieldType.String),
15
+ new IntermediateFieldDefinition(nameof(SqlScriptTupleFields.ComponentRef), IntermediateFieldType.String),
16
+ new IntermediateFieldDefinition(nameof(SqlScriptTupleFields.ScriptBinaryRef), IntermediateFieldType.String),
17
+ new IntermediateFieldDefinition(nameof(SqlScriptTupleFields.UserRef), IntermediateFieldType.String),
18
new IntermediateFieldDefinition(nameof(SqlScriptTupleFields.Attributes), IntermediateFieldType.Number),
19
new IntermediateFieldDefinition(nameof(SqlScriptTupleFields.Sequence), IntermediateFieldType.Number),
20
},
@@ -29,11 +28,10 @@ namespace WixToolset.Sql.Tuples
28
29
public enum SqlScriptTupleFields
30
{
32
- Script,
33
- SqlDb_,
34
- Component_,
35
- ScriptBinary_,
36
- User_,
31
+ SqlDbRef,
32
+ ComponentRef,
33
+ ScriptBinaryRef,
34
+ UserRef,
35
Attributes,
36
Sequence,
37
}
@@ -50,34 +48,28 @@ namespace WixToolset.Sql.Tuples
48
49
public IntermediateField this[SqlScriptTupleFields index] => this.Fields[(int)index];
50
53
- public string Script
51
+ public string SqlDbRef
52
{
55
- get => this.Fields[(int)SqlScriptTupleFields.Script].AsString();
56
- set => this.Set((int)SqlScriptTupleFields.Script, value);
53
+ get => this.Fields[(int)SqlScriptTupleFields.SqlDbRef].AsString();
54
+ set => this.Set((int)SqlScriptTupleFields.SqlDbRef, value);
55
}
56
59
- public string SqlDb_
57
+ public string ComponentRef
58
{
61
- get => this.Fields[(int)SqlScriptTupleFields.SqlDb_].AsString();
62
- set => this.Set((int)SqlScriptTupleFields.SqlDb_, value);
59
+ get => this.Fields[(int)SqlScriptTupleFields.ComponentRef].AsString();
60
+ set => this.Set((int)SqlScriptTupleFields.ComponentRef, value);
61
}
62
65
- public string Component_
63
+ public string ScriptBinaryRef
64
{
67
- get => this.Fields[(int)SqlScriptTupleFields.Component_].AsString();
68
- set => this.Set((int)SqlScriptTupleFields.Component_, value);
65
+ get => this.Fields[(int)SqlScriptTupleFields.ScriptBinaryRef].AsString();
66
+ set => this.Set((int)SqlScriptTupleFields.ScriptBinaryRef, value);
67
}
68
71
- public string ScriptBinary_
69
+ public string UserRef
70
{
73
- get => this.Fields[(int)SqlScriptTupleFields.ScriptBinary_].AsString();
74
- set => this.Set((int)SqlScriptTupleFields.ScriptBinary_, value);
75
- }
76
-
77
- public string User_
78
- {
79
- get => this.Fields[(int)SqlScriptTupleFields.User_].AsString();
80
- set => this.Set((int)SqlScriptTupleFields.User_, value);
71
+ get => this.Fields[(int)SqlScriptTupleFields.UserRef].AsString();
72
+ set => this.Set((int)SqlScriptTupleFields.UserRef, value);
73
}
74
75
public int Attributes
src/wixext/Tuples/SqlStringTuple.cs
+15
-23
@@ -11,11 +11,10 @@ namespace WixToolset.Sql
11
SqlTupleDefinitionType.SqlString.ToString(),
12
new[]
13
{
14
- new IntermediateFieldDefinition(nameof(SqlStringTupleFields.String), IntermediateFieldType.String),
15
- new IntermediateFieldDefinition(nameof(SqlStringTupleFields.SqlDb_), IntermediateFieldType.String),
16
- new IntermediateFieldDefinition(nameof(SqlStringTupleFields.Component_), IntermediateFieldType.String),
14
+ new IntermediateFieldDefinition(nameof(SqlStringTupleFields.SqlDbRef), IntermediateFieldType.String),
15
+ new IntermediateFieldDefinition(nameof(SqlStringTupleFields.ComponentRef), IntermediateFieldType.String),
16
new IntermediateFieldDefinition(nameof(SqlStringTupleFields.SQL), IntermediateFieldType.String),
18
- new IntermediateFieldDefinition(nameof(SqlStringTupleFields.User_), IntermediateFieldType.String),
17
+ new IntermediateFieldDefinition(nameof(SqlStringTupleFields.UserRef), IntermediateFieldType.String),
18
new IntermediateFieldDefinition(nameof(SqlStringTupleFields.Attributes), IntermediateFieldType.Number),
19
new IntermediateFieldDefinition(nameof(SqlStringTupleFields.Sequence), IntermediateFieldType.Number),
20
},
@@ -29,11 +28,10 @@ namespace WixToolset.Sql.Tuples
28
29
public enum SqlStringTupleFields
30
{
32
- String,
33
- SqlDb_,
34
- Component_,
31
+ SqlDbRef,
32
+ ComponentRef,
33
SQL,
36
- User_,
34
+ UserRef,
35
Attributes,
36
Sequence,
37
}
@@ -50,22 +48,16 @@ namespace WixToolset.Sql.Tuples
48
49
public IntermediateField this[SqlStringTupleFields index] => this.Fields[(int)index];
50
53
- public string String
51
+ public string SqlDbRef
52
{
55
- get => this.Fields[(int)SqlStringTupleFields.String].AsString();
56
- set => this.Set((int)SqlStringTupleFields.String, value);
53
+ get => this.Fields[(int)SqlStringTupleFields.SqlDbRef].AsString();
54
+ set => this.Set((int)SqlStringTupleFields.SqlDbRef, value);
55
}
56
59
- public string SqlDb_
57
+ public string ComponentRef
58
{
61
- get => this.Fields[(int)SqlStringTupleFields.SqlDb_].AsString();
62
- set => this.Set((int)SqlStringTupleFields.SqlDb_, value);
63
- }
64
-
65
- public string Component_
66
- {
67
- get => this.Fields[(int)SqlStringTupleFields.Component_].AsString();
68
- set => this.Set((int)SqlStringTupleFields.Component_, value);
59
+ get => this.Fields[(int)SqlStringTupleFields.ComponentRef].AsString();
60
+ set => this.Set((int)SqlStringTupleFields.ComponentRef, value);
61
}
62
63
public string SQL
@@ -74,10 +66,10 @@ namespace WixToolset.Sql.Tuples
66
set => this.Set((int)SqlStringTupleFields.SQL, value);
67
}
68
77
- public string User_
69
+ public string UserRef
70
{
79
- get => this.Fields[(int)SqlStringTupleFields.User_].AsString();
80
- set => this.Set((int)SqlStringTupleFields.User_, value);
71
+ get => this.Fields[(int)SqlStringTupleFields.UserRef].AsString();
72
+ set => this.Set((int)SqlStringTupleFields.UserRef, value);
73
}
74
75
public int Attributes
src/wixext/WixToolset.Sql.wixext.csproj
-1
@@ -14,7 +14,6 @@
14
<ItemGroup>
15
<Content Include="$(MSBuildThisFileName).targets" />
16
<Content Include="sql.xsd" PackagePath="tools" />
17
- <EmbeddedResource Include="tables.xml" />
17
<EmbeddedResource Include="$(OutputPath)..\sql.wixlib" />
18
</ItemGroup>
19
src/wixext/tables.xml
deleted
-73
@@ -1,73 +0,0 @@
1
-<?xml version="1.0" encoding="utf-8" ?>
2
-<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. -->
3
-
4
-
5
-<tableDefinitions xmlns="http://wixtoolset.org/schemas/v4/wi/tables">
6
- <tableDefinition name="SqlDatabase" createSymbols="yes">
7
- <columnDefinition name="SqlDb" type="string" length="72" primaryKey="yes" modularize="column"
8
- category="identifier" description="Primary key, non-localized token"/>
9
- <columnDefinition name="Server" type="string" length="255" nullable="yes"
10
- category="formatted" description="Primary key, name of server running SQL Server"/>
11
- <columnDefinition name="Instance" type="string" length="255" nullable="yes"
12
- category="formatted" description="Primary key, name of SQL Server instance"/>
13
- <!-- TODO: change the Database column length to "128" in WiX v4.0 when we can put in breaking changes -->
14
- <columnDefinition name="Database" type="string" length="255"
15
- category="formatted" description="Primary key, name of database in a SQL Server"/>
16
- <columnDefinition name="Component_" type="string" length="72" modularize="column" nullable="yes"
17
- keyTable="Component" keyColumn="1" category="identifier" description="Foreign key, Component used to determine install state "/>
18
- <columnDefinition name="User_" type="string" length="72" nullable="yes" modularize="column"
19
- keyTable="User" keyColumn="1" category="identifier" description="Foreign key, User used to log into database"/>
20
- <columnDefinition name="FileSpec_" type="string" length="72" nullable="yes" modularize="column"
21
- keyTable="SqlFileSpec" keyColumn="1" category="identifier" description="Foreign key referencing SqlFileSpec."/>
22
- <columnDefinition name="FileSpec_Log" type="string" length="72" nullable="yes" modularize="column"
23
- keyTable="SqlFileSpec" keyColumn="1" category="identifier" description="Foreign key referencing SqlFileSpec."/>
24
- <columnDefinition name="Attributes" type="number" length="2" nullable="yes"
25
- minValue="0" maxValue="255" description="1 == create on install, 2 == drop on uninstall, 4 == continue on error, 8 == drop on install, 16 == create on uninstall, 32 == confirm update existing table, 64 == create on reinstall, 128 == drop on reinstall" />
26
- </tableDefinition>
27
- <tableDefinition name="SqlFileSpec" createSymbols="yes">
28
- <columnDefinition name="FileSpec" type="string" length="72" primaryKey="yes" modularize="column"
29
- category="identifier" description="Primary key, non-localized token"/>
30
- <columnDefinition name="Name" type="string" length="255" modularize="property"
31
- category="formatted" description="Logical name of filespec"/>
32
- <columnDefinition name="Filename" type="string" length="255" modularize="property"
33
- category="formatted" description="Filename to use (path must exist)"/>
34
- <columnDefinition name="Size" type="string" length="72" nullable="yes" modularize="property"
35
- category="formatted" description="Initial size for file"/>
36
- <columnDefinition name="MaxSize" type="string" length="72" nullable="yes" modularize="property"
37
- category="formatted" description="Maximum size for file"/>
38
- <columnDefinition name="GrowthSize" type="string" length="72" nullable="yes" modularize="property"
39
- category="formatted" description="Size file should grow when necessary"/>
40
- </tableDefinition>
41
- <tableDefinition name="SqlScript">
42
- <columnDefinition name="Script" type="string" length="72" primaryKey="yes"
43
- category="identifier" description="Primary key, non-localized token"/>
44
- <columnDefinition name="SqlDb_" type="string" length="72" modularize="column"
45
- keyTable="SqlDatabase" keyColumn="1" category="identifier" description="Foreign key, SQL Server key"/>
46
- <columnDefinition name="Component_" type="string" length="72" modularize="column"
47
- keyTable="Component" keyColumn="1" category="identifier" description="Foreign key, Component used to determine install state"/>
48
- <columnDefinition name="ScriptBinary_" type="string" length="72" modularize="column"
49
- keyTable="Binary" keyColumn="1" category="identifier" description="Foreign key, Binary stream that contains SQL Script to execute"/>
50
- <columnDefinition name="User_" type="string" length="72" nullable="yes" modularize="column"
51
- keyTable="User" keyColumn="1" category="identifier" description="Foreign key, User used to log into database"/>
52
- <columnDefinition name="Attributes" type="number" length="2"
53
- set="1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24;25;26;27;28;29;30;31" description="1 == execute on install, 2 == execute on uninstall, 4 == continue on error, 8 == rollback on install, 16 == rollback on uninstall"/>
54
- <columnDefinition name="Sequence" type="number" length="2" nullable="yes"
55
- description="Order to execute SQL Queries in"/>
56
- </tableDefinition>
57
- <tableDefinition name="SqlString">
58
- <columnDefinition name="String" type="string" length="72" modularize="column" primaryKey="yes"
59
- category="identifier" description="Id for the SqlString" />
60
- <columnDefinition name="SqlDb_" type="string" length="72" modularize="column"
61
- keyTable="SqlDatabase" keyColumn="1" category="identifier" description="Foreign key, SQL Server key"/>
62
- <columnDefinition name="Component_" type="string" length="72" modularize="column"
63
- keyTable="Component" keyColumn="1" category="identifier" description="Foreign key, Component used to determine install state"/>
64
- <columnDefinition name="SQL" type="string" length="0"
65
- category="formatted" description="SQL query to execute" escapeIdtCharacters="yes"/>
66
- <columnDefinition name="User_" type="string" length="72" nullable="yes" modularize="column"
67
- keyTable="User" keyColumn="1" category="identifier" description="Foreign key, User used to log into database"/>
68
- <columnDefinition name="Attributes" type="number" length="2"
69
- set="1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24;25;26;27;28;29;30;31" description="1 == execute on install, 2 == execute on uninstall, 4 == continue on error, 8 == rollback on install, 16 == rollback on uninstall"/>
70
- <columnDefinition name="Sequence" type="number" length="2" nullable="yes"
71
- description="Order to execute SQL Queries in"/>
72
- </tableDefinition>
73
-</tableDefinitions>