@joebigelow / wix / commits / 2dcc5190

Add tuple definitions and fix test.

Sean Hall committed Jan 2, 2019 at 22:33 UTC 2dcc519054be041ef5aa6cfac9dac13b0ea04eca
9 files changed +447 -8
src/test/WixToolsetTest.Sql/SqlExtensionFixture.cs
+1 -1
@@ -19,7 +19,7 @@ namespace WixToolsetTest.Sql
19 var results = build.BuildAndQuery(Build, "SqlString");
20 Assert.Equal(new[]
21 {
22 - "SqlString:",
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());
24 }
25
src/test/WixToolsetTest.Sql/TestData/UsingSql/PackageComponents.wxs
+2 -2
@@ -3,8 +3,8 @@
3 xmlns:sql="http://wixtoolset.org/schemas/v4/wxs/sql">
4 <Fragment>
5 <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
6 - <Component KeyPath="yes">
7 - <CreateFolder />
6 + <Component>
7 + <File Source="example.txt" />
8 <sql:SqlDatabase Id="TestDB" Database="MyDB" Server="MySQLHostName" Instance="MyInstanceName" CreateOnInstall="yes" DropOnUninstall="yes" ConfirmOverwrite="yes">
9 <sql:SqlString Id="TestString" SQL="CREATE TABLE TestTable1(name varchar(20), value varchar(20))" ExecuteOnInstall="yes" />
10 </sql:SqlDatabase>
src/wixext/SqlCompiler.cs
+4 -4
@@ -265,7 +265,7 @@ namespace WixToolset.Sql
265 this.Messaging.Write(SqlErrors.IllegalElementWithoutComponent(childSourceLineNumbers, child.Name.LocalName));
266 }
267
268 - this.ParseSqlScriptElement(intermediate, section, child, componentId, id.Id);
268 + this.ParseSqlScriptElement(intermediate, section, child, componentId, id?.Id);
269 break;
270 case "SqlString":
271 if (null == componentId)
@@ -273,7 +273,7 @@ namespace WixToolset.Sql
273 this.Messaging.Write(SqlErrors.IllegalElementWithoutComponent(childSourceLineNumbers, child.Name.LocalName));
274 }
275
276 - this.ParseSqlStringElement(intermediate, section, child, componentId, id.Id);
276 + this.ParseSqlStringElement(intermediate, section, child, componentId, id?.Id);
277 break;
278 case "SqlFileSpec":
279 if (null == componentId)
@@ -325,8 +325,8 @@ namespace WixToolset.Sql
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);
328 + row.Set(6, fileSpec?.Id);
329 + row.Set(7, logFileSpec?.Id);
330 if (0 != attributes)
331 {
332 row.Set(8, attributes);
src/wixext/SqlExtensionData.cs
+1 -1
@@ -18,7 +18,7 @@ namespace WixToolset.Sql
18
19 public override bool TryGetTupleDefinitionByName(string name, out IntermediateTupleDefinition tupleDefinition)
20 {
21 - tupleDefinition = null;
21 + tupleDefinition = SqlTupleDefinitions.ByName(name);
22 return tupleDefinition != null;
23 }
24
src/wixext/Tuples/SqlDatabaseTuple.cs new
+111
@@ -0,0 +1,111 @@
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;
6 + using WixToolset.Sql.Tuples;
7 +
8 + public static partial class SqlTupleDefinitions
9 + {
10 + public static readonly IntermediateTupleDefinition SqlDatabase = new IntermediateTupleDefinition(
11 + SqlTupleDefinitionType.SqlDatabase.ToString(),
12 + new[]
13 + {
14 + new IntermediateFieldDefinition(nameof(SqlDatabaseTupleFields.SqlDb), IntermediateFieldType.String),
15 + new IntermediateFieldDefinition(nameof(SqlDatabaseTupleFields.Server), IntermediateFieldType.String),
16 + new IntermediateFieldDefinition(nameof(SqlDatabaseTupleFields.Instance), IntermediateFieldType.String),
17 + 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),
22 + new IntermediateFieldDefinition(nameof(SqlDatabaseTupleFields.Attributes), IntermediateFieldType.Number),
23 + },
24 + typeof(SqlDatabaseTuple));
25 + }
26 +}
27 +
28 +namespace WixToolset.Sql.Tuples
29 +{
30 + using WixToolset.Data;
31 +
32 + public enum SqlDatabaseTupleFields
33 + {
34 + SqlDb,
35 + Server,
36 + Instance,
37 + Database,
38 + Component_,
39 + User_,
40 + FileSpec_,
41 + FileSpec_Log,
42 + Attributes,
43 + }
44 +
45 + public class SqlDatabaseTuple : IntermediateTuple
46 + {
47 + public SqlDatabaseTuple() : base(SqlTupleDefinitions.SqlDatabase, null, null)
48 + {
49 + }
50 +
51 + public SqlDatabaseTuple(SourceLineNumber sourceLineNumber, Identifier id = null) : base(SqlTupleDefinitions.SqlDatabase, sourceLineNumber, id)
52 + {
53 + }
54 +
55 + public IntermediateField this[SqlDatabaseTupleFields index] => this.Fields[(int)index];
56 +
57 + public string SqlDb
58 + {
59 + get => this.Fields[(int)SqlDatabaseTupleFields.SqlDb].AsString();
60 + set => this.Set((int)SqlDatabaseTupleFields.SqlDb, value);
61 + }
62 +
63 + public string Server
64 + {
65 + get => this.Fields[(int)SqlDatabaseTupleFields.Server].AsString();
66 + set => this.Set((int)SqlDatabaseTupleFields.Server, value);
67 + }
68 +
69 + public string Instance
70 + {
71 + get => this.Fields[(int)SqlDatabaseTupleFields.Instance].AsString();
72 + set => this.Set((int)SqlDatabaseTupleFields.Instance, value);
73 + }
74 +
75 + public string Database
76 + {
77 + get => this.Fields[(int)SqlDatabaseTupleFields.Database].AsString();
78 + set => this.Set((int)SqlDatabaseTupleFields.Database, value);
79 + }
80 +
81 + public string Component_
82 + {
83 + get => this.Fields[(int)SqlDatabaseTupleFields.Component_].AsString();
84 + set => this.Set((int)SqlDatabaseTupleFields.Component_, value);
85 + }
86 +
87 + public string User_
88 + {
89 + get => this.Fields[(int)SqlDatabaseTupleFields.User_].AsString();
90 + set => this.Set((int)SqlDatabaseTupleFields.User_, value);
91 + }
92 +
93 + public string FileSpec_
94 + {
95 + get => this.Fields[(int)SqlDatabaseTupleFields.FileSpec_].AsString();
96 + set => this.Set((int)SqlDatabaseTupleFields.FileSpec_, value);
97 + }
98 +
99 + public string FileSpec_Log
100 + {
101 + get => this.Fields[(int)SqlDatabaseTupleFields.FileSpec_Log].AsString();
102 + set => this.Set((int)SqlDatabaseTupleFields.FileSpec_Log, value);
103 + }
104 +
105 + public int Attributes
106 + {
107 + get => this.Fields[(int)SqlDatabaseTupleFields.Attributes].AsNumber();
108 + set => this.Set((int)SqlDatabaseTupleFields.Attributes, value);
109 + }
110 + }
111 +}
\ No newline at end of file
src/wixext/Tuples/SqlFileSpecTuple.cs new
+87
@@ -0,0 +1,87 @@
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;
6 + using WixToolset.Sql.Tuples;
7 +
8 + public static partial class SqlTupleDefinitions
9 + {
10 + public static readonly IntermediateTupleDefinition SqlFileSpec = new IntermediateTupleDefinition(
11 + SqlTupleDefinitionType.SqlFileSpec.ToString(),
12 + new[]
13 + {
14 + new IntermediateFieldDefinition(nameof(SqlFileSpecTupleFields.FileSpec), IntermediateFieldType.String),
15 + new IntermediateFieldDefinition(nameof(SqlFileSpecTupleFields.Name), IntermediateFieldType.String),
16 + new IntermediateFieldDefinition(nameof(SqlFileSpecTupleFields.Filename), IntermediateFieldType.String),
17 + new IntermediateFieldDefinition(nameof(SqlFileSpecTupleFields.Size), IntermediateFieldType.String),
18 + new IntermediateFieldDefinition(nameof(SqlFileSpecTupleFields.MaxSize), IntermediateFieldType.String),
19 + new IntermediateFieldDefinition(nameof(SqlFileSpecTupleFields.GrowthSize), IntermediateFieldType.String),
20 + },
21 + typeof(SqlFileSpecTuple));
22 + }
23 +}
24 +
25 +namespace WixToolset.Sql.Tuples
26 +{
27 + using WixToolset.Data;
28 +
29 + public enum SqlFileSpecTupleFields
30 + {
31 + FileSpec,
32 + Name,
33 + Filename,
34 + Size,
35 + MaxSize,
36 + GrowthSize,
37 + }
38 +
39 + public class SqlFileSpecTuple : IntermediateTuple
40 + {
41 + public SqlFileSpecTuple() : base(SqlTupleDefinitions.SqlFileSpec, null, null)
42 + {
43 + }
44 +
45 + public SqlFileSpecTuple(SourceLineNumber sourceLineNumber, Identifier id = null) : base(SqlTupleDefinitions.SqlFileSpec, sourceLineNumber, id)
46 + {
47 + }
48 +
49 + public IntermediateField this[SqlFileSpecTupleFields index] => this.Fields[(int)index];
50 +
51 + public string FileSpec
52 + {
53 + get => this.Fields[(int)SqlFileSpecTupleFields.FileSpec].AsString();
54 + set => this.Set((int)SqlFileSpecTupleFields.FileSpec, value);
55 + }
56 +
57 + public string Name
58 + {
59 + get => this.Fields[(int)SqlFileSpecTupleFields.Name].AsString();
60 + set => this.Set((int)SqlFileSpecTupleFields.Name, value);
61 + }
62 +
63 + public string Filename
64 + {
65 + get => this.Fields[(int)SqlFileSpecTupleFields.Filename].AsString();
66 + set => this.Set((int)SqlFileSpecTupleFields.Filename, value);
67 + }
68 +
69 + public string Size
70 + {
71 + get => this.Fields[(int)SqlFileSpecTupleFields.Size].AsString();
72 + set => this.Set((int)SqlFileSpecTupleFields.Size, value);
73 + }
74 +
75 + public string MaxSize
76 + {
77 + get => this.Fields[(int)SqlFileSpecTupleFields.MaxSize].AsString();
78 + set => this.Set((int)SqlFileSpecTupleFields.MaxSize, value);
79 + }
80 +
81 + public string GrowthSize
82 + {
83 + get => this.Fields[(int)SqlFileSpecTupleFields.GrowthSize].AsString();
84 + set => this.Set((int)SqlFileSpecTupleFields.GrowthSize, value);
85 + }
86 + }
87 +}
\ No newline at end of file
src/wixext/Tuples/SqlScriptTuple.cs new
+95
@@ -0,0 +1,95 @@
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;
6 + using WixToolset.Sql.Tuples;
7 +
8 + public static partial class SqlTupleDefinitions
9 + {
10 + public static readonly IntermediateTupleDefinition SqlScript = new IntermediateTupleDefinition(
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),
19 + new IntermediateFieldDefinition(nameof(SqlScriptTupleFields.Attributes), IntermediateFieldType.Number),
20 + new IntermediateFieldDefinition(nameof(SqlScriptTupleFields.Sequence), IntermediateFieldType.Number),
21 + },
22 + typeof(SqlScriptTuple));
23 + }
24 +}
25 +
26 +namespace WixToolset.Sql.Tuples
27 +{
28 + using WixToolset.Data;
29 +
30 + public enum SqlScriptTupleFields
31 + {
32 + Script,
33 + SqlDb_,
34 + Component_,
35 + ScriptBinary_,
36 + User_,
37 + Attributes,
38 + Sequence,
39 + }
40 +
41 + public class SqlScriptTuple : IntermediateTuple
42 + {
43 + public SqlScriptTuple() : base(SqlTupleDefinitions.SqlScript, null, null)
44 + {
45 + }
46 +
47 + public SqlScriptTuple(SourceLineNumber sourceLineNumber, Identifier id = null) : base(SqlTupleDefinitions.SqlScript, sourceLineNumber, id)
48 + {
49 + }
50 +
51 + public IntermediateField this[SqlScriptTupleFields index] => this.Fields[(int)index];
52 +
53 + public string Script
54 + {
55 + get => this.Fields[(int)SqlScriptTupleFields.Script].AsString();
56 + set => this.Set((int)SqlScriptTupleFields.Script, value);
57 + }
58 +
59 + public string SqlDb_
60 + {
61 + get => this.Fields[(int)SqlScriptTupleFields.SqlDb_].AsString();
62 + set => this.Set((int)SqlScriptTupleFields.SqlDb_, value);
63 + }
64 +
65 + public string Component_
66 + {
67 + get => this.Fields[(int)SqlScriptTupleFields.Component_].AsString();
68 + set => this.Set((int)SqlScriptTupleFields.Component_, value);
69 + }
70 +
71 + public string ScriptBinary_
72 + {
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);
81 + }
82 +
83 + public int Attributes
84 + {
85 + get => this.Fields[(int)SqlScriptTupleFields.Attributes].AsNumber();
86 + set => this.Set((int)SqlScriptTupleFields.Attributes, value);
87 + }
88 +
89 + public int Sequence
90 + {
91 + get => this.Fields[(int)SqlScriptTupleFields.Sequence].AsNumber();
92 + set => this.Set((int)SqlScriptTupleFields.Sequence, value);
93 + }
94 + }
95 +}
\ No newline at end of file
src/wixext/Tuples/SqlStringTuple.cs new
+95
@@ -0,0 +1,95 @@
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;
6 + using WixToolset.Sql.Tuples;
7 +
8 + public static partial class SqlTupleDefinitions
9 + {
10 + public static readonly IntermediateTupleDefinition SqlString = new IntermediateTupleDefinition(
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),
17 + new IntermediateFieldDefinition(nameof(SqlStringTupleFields.SQL), IntermediateFieldType.String),
18 + new IntermediateFieldDefinition(nameof(SqlStringTupleFields.User_), IntermediateFieldType.String),
19 + new IntermediateFieldDefinition(nameof(SqlStringTupleFields.Attributes), IntermediateFieldType.Number),
20 + new IntermediateFieldDefinition(nameof(SqlStringTupleFields.Sequence), IntermediateFieldType.Number),
21 + },
22 + typeof(SqlStringTuple));
23 + }
24 +}
25 +
26 +namespace WixToolset.Sql.Tuples
27 +{
28 + using WixToolset.Data;
29 +
30 + public enum SqlStringTupleFields
31 + {
32 + String,
33 + SqlDb_,
34 + Component_,
35 + SQL,
36 + User_,
37 + Attributes,
38 + Sequence,
39 + }
40 +
41 + public class SqlStringTuple : IntermediateTuple
42 + {
43 + public SqlStringTuple() : base(SqlTupleDefinitions.SqlString, null, null)
44 + {
45 + }
46 +
47 + public SqlStringTuple(SourceLineNumber sourceLineNumber, Identifier id = null) : base(SqlTupleDefinitions.SqlString, sourceLineNumber, id)
48 + {
49 + }
50 +
51 + public IntermediateField this[SqlStringTupleFields index] => this.Fields[(int)index];
52 +
53 + public string String
54 + {
55 + get => this.Fields[(int)SqlStringTupleFields.String].AsString();
56 + set => this.Set((int)SqlStringTupleFields.String, value);
57 + }
58 +
59 + public string SqlDb_
60 + {
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);
69 + }
70 +
71 + public string SQL
72 + {
73 + get => this.Fields[(int)SqlStringTupleFields.SQL].AsString();
74 + set => this.Set((int)SqlStringTupleFields.SQL, value);
75 + }
76 +
77 + public string User_
78 + {
79 + get => this.Fields[(int)SqlStringTupleFields.User_].AsString();
80 + set => this.Set((int)SqlStringTupleFields.User_, value);
81 + }
82 +
83 + public int Attributes
84 + {
85 + get => this.Fields[(int)SqlStringTupleFields.Attributes].AsNumber();
86 + set => this.Set((int)SqlStringTupleFields.Attributes, value);
87 + }
88 +
89 + public int Sequence
90 + {
91 + get => this.Fields[(int)SqlStringTupleFields.Sequence].AsNumber();
92 + set => this.Set((int)SqlStringTupleFields.Sequence, value);
93 + }
94 + }
95 +}
\ No newline at end of file
src/wixext/Tuples/SqlTupleDefinitions.cs new
+51
@@ -0,0 +1,51 @@
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;
6 + using WixToolset.Data;
7 +
8 + public enum SqlTupleDefinitionType
9 + {
10 + SqlDatabase,
11 + SqlFileSpec,
12 + SqlScript,
13 + SqlString,
14 + }
15 +
16 + public static partial class SqlTupleDefinitions
17 + {
18 + public static readonly Version Version = new Version("4.0.0");
19 +
20 + public static IntermediateTupleDefinition ByName(string name)
21 + {
22 + if (!Enum.TryParse(name, out SqlTupleDefinitionType type))
23 + {
24 + return null;
25 + }
26 +
27 + return ByType(type);
28 + }
29 +
30 + public static IntermediateTupleDefinition ByType(SqlTupleDefinitionType type)
31 + {
32 + switch (type)
33 + {
34 + case SqlTupleDefinitionType.SqlDatabase:
35 + return SqlTupleDefinitions.SqlDatabase;
36 +
37 + case SqlTupleDefinitionType.SqlFileSpec:
38 + return SqlTupleDefinitions.SqlFileSpec;
39 +
40 + case SqlTupleDefinitionType.SqlScript:
41 + return SqlTupleDefinitions.SqlScript;
42 +
43 + case SqlTupleDefinitionType.SqlString:
44 + return SqlTupleDefinitions.SqlString;
45 +
46 + default:
47 + throw new ArgumentOutOfRangeException(nameof(type));
48 + }
49 + }
50 + }
51 +}