From 2dcc519054be041ef5aa6cfac9dac13b0ea04eca Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Wed, 2 Jan 2019 22:33:22 -0600 Subject: Add tuple definitions and fix test. --- src/test/WixToolsetTest.Sql/SqlExtensionFixture.cs | 2 +- .../TestData/UsingSql/PackageComponents.wxs | 4 +- src/wixext/SqlCompiler.cs | 8 +- src/wixext/SqlExtensionData.cs | 2 +- src/wixext/Tuples/SqlDatabaseTuple.cs | 111 +++++++++++++++++++++ src/wixext/Tuples/SqlFileSpecTuple.cs | 87 ++++++++++++++++ src/wixext/Tuples/SqlScriptTuple.cs | 95 ++++++++++++++++++ src/wixext/Tuples/SqlStringTuple.cs | 95 ++++++++++++++++++ src/wixext/Tuples/SqlTupleDefinitions.cs | 51 ++++++++++ 9 files changed, 447 insertions(+), 8 deletions(-) create mode 100644 src/wixext/Tuples/SqlDatabaseTuple.cs create mode 100644 src/wixext/Tuples/SqlFileSpecTuple.cs create mode 100644 src/wixext/Tuples/SqlScriptTuple.cs create mode 100644 src/wixext/Tuples/SqlStringTuple.cs create mode 100644 src/wixext/Tuples/SqlTupleDefinitions.cs diff --git a/src/test/WixToolsetTest.Sql/SqlExtensionFixture.cs b/src/test/WixToolsetTest.Sql/SqlExtensionFixture.cs index 831bcd83..d7fe74e6 100644 --- a/src/test/WixToolsetTest.Sql/SqlExtensionFixture.cs +++ b/src/test/WixToolsetTest.Sql/SqlExtensionFixture.cs @@ -19,7 +19,7 @@ namespace WixToolsetTest.Sql var results = build.BuildAndQuery(Build, "SqlString"); Assert.Equal(new[] { - "SqlString:", + "SqlString:TestString\tTestDB\tfilF5_pLhBuF5b4N9XEo52g_hUM5Lo\tCREATE TABLE TestTable1(name varchar(20), value varchar(20))\t\t1\t0", }, results.OrderBy(s => s).ToArray()); } diff --git a/src/test/WixToolsetTest.Sql/TestData/UsingSql/PackageComponents.wxs b/src/test/WixToolsetTest.Sql/TestData/UsingSql/PackageComponents.wxs index d2572659..653f7e02 100644 --- a/src/test/WixToolsetTest.Sql/TestData/UsingSql/PackageComponents.wxs +++ b/src/test/WixToolsetTest.Sql/TestData/UsingSql/PackageComponents.wxs @@ -3,8 +3,8 @@ xmlns:sql="http://wixtoolset.org/schemas/v4/wxs/sql"> - - + + diff --git a/src/wixext/SqlCompiler.cs b/src/wixext/SqlCompiler.cs index c789f3bd..3fb33993 100644 --- a/src/wixext/SqlCompiler.cs +++ b/src/wixext/SqlCompiler.cs @@ -265,7 +265,7 @@ namespace WixToolset.Sql this.Messaging.Write(SqlErrors.IllegalElementWithoutComponent(childSourceLineNumbers, child.Name.LocalName)); } - this.ParseSqlScriptElement(intermediate, section, child, componentId, id.Id); + this.ParseSqlScriptElement(intermediate, section, child, componentId, id?.Id); break; case "SqlString": if (null == componentId) @@ -273,7 +273,7 @@ namespace WixToolset.Sql this.Messaging.Write(SqlErrors.IllegalElementWithoutComponent(childSourceLineNumbers, child.Name.LocalName)); } - this.ParseSqlStringElement(intermediate, section, child, componentId, id.Id); + this.ParseSqlStringElement(intermediate, section, child, componentId, id?.Id); break; case "SqlFileSpec": if (null == componentId) @@ -325,8 +325,8 @@ namespace WixToolset.Sql row.Set(3, database); row.Set(4, componentId); row.Set(5, user); - row.Set(6, fileSpec.Id); - row.Set(7, logFileSpec.Id); + row.Set(6, fileSpec?.Id); + row.Set(7, logFileSpec?.Id); if (0 != attributes) { row.Set(8, attributes); diff --git a/src/wixext/SqlExtensionData.cs b/src/wixext/SqlExtensionData.cs index a1b24b07..e27b698f 100644 --- a/src/wixext/SqlExtensionData.cs +++ b/src/wixext/SqlExtensionData.cs @@ -18,7 +18,7 @@ namespace WixToolset.Sql public override bool TryGetTupleDefinitionByName(string name, out IntermediateTupleDefinition tupleDefinition) { - tupleDefinition = null; + tupleDefinition = SqlTupleDefinitions.ByName(name); return tupleDefinition != null; } diff --git a/src/wixext/Tuples/SqlDatabaseTuple.cs b/src/wixext/Tuples/SqlDatabaseTuple.cs new file mode 100644 index 00000000..fd107690 --- /dev/null +++ b/src/wixext/Tuples/SqlDatabaseTuple.cs @@ -0,0 +1,111 @@ +// 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. + +namespace WixToolset.Sql +{ + using WixToolset.Data; + using WixToolset.Sql.Tuples; + + public static partial class SqlTupleDefinitions + { + public static readonly IntermediateTupleDefinition SqlDatabase = new IntermediateTupleDefinition( + SqlTupleDefinitionType.SqlDatabase.ToString(), + new[] + { + new IntermediateFieldDefinition(nameof(SqlDatabaseTupleFields.SqlDb), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(SqlDatabaseTupleFields.Server), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(SqlDatabaseTupleFields.Instance), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(SqlDatabaseTupleFields.Database), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(SqlDatabaseTupleFields.Component_), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(SqlDatabaseTupleFields.User_), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(SqlDatabaseTupleFields.FileSpec_), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(SqlDatabaseTupleFields.FileSpec_Log), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(SqlDatabaseTupleFields.Attributes), IntermediateFieldType.Number), + }, + typeof(SqlDatabaseTuple)); + } +} + +namespace WixToolset.Sql.Tuples +{ + using WixToolset.Data; + + public enum SqlDatabaseTupleFields + { + SqlDb, + Server, + Instance, + Database, + Component_, + User_, + FileSpec_, + FileSpec_Log, + Attributes, + } + + public class SqlDatabaseTuple : IntermediateTuple + { + public SqlDatabaseTuple() : base(SqlTupleDefinitions.SqlDatabase, null, null) + { + } + + public SqlDatabaseTuple(SourceLineNumber sourceLineNumber, Identifier id = null) : base(SqlTupleDefinitions.SqlDatabase, sourceLineNumber, id) + { + } + + public IntermediateField this[SqlDatabaseTupleFields index] => this.Fields[(int)index]; + + public string SqlDb + { + get => this.Fields[(int)SqlDatabaseTupleFields.SqlDb].AsString(); + set => this.Set((int)SqlDatabaseTupleFields.SqlDb, value); + } + + public string Server + { + get => this.Fields[(int)SqlDatabaseTupleFields.Server].AsString(); + set => this.Set((int)SqlDatabaseTupleFields.Server, value); + } + + public string Instance + { + get => this.Fields[(int)SqlDatabaseTupleFields.Instance].AsString(); + set => this.Set((int)SqlDatabaseTupleFields.Instance, value); + } + + public string Database + { + get => this.Fields[(int)SqlDatabaseTupleFields.Database].AsString(); + set => this.Set((int)SqlDatabaseTupleFields.Database, value); + } + + public string Component_ + { + get => this.Fields[(int)SqlDatabaseTupleFields.Component_].AsString(); + set => this.Set((int)SqlDatabaseTupleFields.Component_, value); + } + + public string User_ + { + get => this.Fields[(int)SqlDatabaseTupleFields.User_].AsString(); + set => this.Set((int)SqlDatabaseTupleFields.User_, value); + } + + public string FileSpec_ + { + get => this.Fields[(int)SqlDatabaseTupleFields.FileSpec_].AsString(); + set => this.Set((int)SqlDatabaseTupleFields.FileSpec_, value); + } + + public string FileSpec_Log + { + get => this.Fields[(int)SqlDatabaseTupleFields.FileSpec_Log].AsString(); + set => this.Set((int)SqlDatabaseTupleFields.FileSpec_Log, value); + } + + public int Attributes + { + get => this.Fields[(int)SqlDatabaseTupleFields.Attributes].AsNumber(); + set => this.Set((int)SqlDatabaseTupleFields.Attributes, value); + } + } +} \ No newline at end of file diff --git a/src/wixext/Tuples/SqlFileSpecTuple.cs b/src/wixext/Tuples/SqlFileSpecTuple.cs new file mode 100644 index 00000000..9813ec83 --- /dev/null +++ b/src/wixext/Tuples/SqlFileSpecTuple.cs @@ -0,0 +1,87 @@ +// 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. + +namespace WixToolset.Sql +{ + using WixToolset.Data; + using WixToolset.Sql.Tuples; + + public static partial class SqlTupleDefinitions + { + public static readonly IntermediateTupleDefinition SqlFileSpec = new IntermediateTupleDefinition( + SqlTupleDefinitionType.SqlFileSpec.ToString(), + new[] + { + new IntermediateFieldDefinition(nameof(SqlFileSpecTupleFields.FileSpec), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(SqlFileSpecTupleFields.Name), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(SqlFileSpecTupleFields.Filename), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(SqlFileSpecTupleFields.Size), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(SqlFileSpecTupleFields.MaxSize), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(SqlFileSpecTupleFields.GrowthSize), IntermediateFieldType.String), + }, + typeof(SqlFileSpecTuple)); + } +} + +namespace WixToolset.Sql.Tuples +{ + using WixToolset.Data; + + public enum SqlFileSpecTupleFields + { + FileSpec, + Name, + Filename, + Size, + MaxSize, + GrowthSize, + } + + public class SqlFileSpecTuple : IntermediateTuple + { + public SqlFileSpecTuple() : base(SqlTupleDefinitions.SqlFileSpec, null, null) + { + } + + public SqlFileSpecTuple(SourceLineNumber sourceLineNumber, Identifier id = null) : base(SqlTupleDefinitions.SqlFileSpec, sourceLineNumber, id) + { + } + + public IntermediateField this[SqlFileSpecTupleFields index] => this.Fields[(int)index]; + + public string FileSpec + { + get => this.Fields[(int)SqlFileSpecTupleFields.FileSpec].AsString(); + set => this.Set((int)SqlFileSpecTupleFields.FileSpec, value); + } + + public string Name + { + get => this.Fields[(int)SqlFileSpecTupleFields.Name].AsString(); + set => this.Set((int)SqlFileSpecTupleFields.Name, value); + } + + public string Filename + { + get => this.Fields[(int)SqlFileSpecTupleFields.Filename].AsString(); + set => this.Set((int)SqlFileSpecTupleFields.Filename, value); + } + + public string Size + { + get => this.Fields[(int)SqlFileSpecTupleFields.Size].AsString(); + set => this.Set((int)SqlFileSpecTupleFields.Size, value); + } + + public string MaxSize + { + get => this.Fields[(int)SqlFileSpecTupleFields.MaxSize].AsString(); + set => this.Set((int)SqlFileSpecTupleFields.MaxSize, value); + } + + public string GrowthSize + { + get => this.Fields[(int)SqlFileSpecTupleFields.GrowthSize].AsString(); + set => this.Set((int)SqlFileSpecTupleFields.GrowthSize, value); + } + } +} \ No newline at end of file diff --git a/src/wixext/Tuples/SqlScriptTuple.cs b/src/wixext/Tuples/SqlScriptTuple.cs new file mode 100644 index 00000000..b1f95709 --- /dev/null +++ b/src/wixext/Tuples/SqlScriptTuple.cs @@ -0,0 +1,95 @@ +// 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. + +namespace WixToolset.Sql +{ + using WixToolset.Data; + using WixToolset.Sql.Tuples; + + public static partial class SqlTupleDefinitions + { + public static readonly IntermediateTupleDefinition SqlScript = new IntermediateTupleDefinition( + SqlTupleDefinitionType.SqlScript.ToString(), + new[] + { + new IntermediateFieldDefinition(nameof(SqlScriptTupleFields.Script), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(SqlScriptTupleFields.SqlDb_), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(SqlScriptTupleFields.Component_), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(SqlScriptTupleFields.ScriptBinary_), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(SqlScriptTupleFields.User_), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(SqlScriptTupleFields.Attributes), IntermediateFieldType.Number), + new IntermediateFieldDefinition(nameof(SqlScriptTupleFields.Sequence), IntermediateFieldType.Number), + }, + typeof(SqlScriptTuple)); + } +} + +namespace WixToolset.Sql.Tuples +{ + using WixToolset.Data; + + public enum SqlScriptTupleFields + { + Script, + SqlDb_, + Component_, + ScriptBinary_, + User_, + Attributes, + Sequence, + } + + public class SqlScriptTuple : IntermediateTuple + { + public SqlScriptTuple() : base(SqlTupleDefinitions.SqlScript, null, null) + { + } + + public SqlScriptTuple(SourceLineNumber sourceLineNumber, Identifier id = null) : base(SqlTupleDefinitions.SqlScript, sourceLineNumber, id) + { + } + + public IntermediateField this[SqlScriptTupleFields index] => this.Fields[(int)index]; + + public string Script + { + get => this.Fields[(int)SqlScriptTupleFields.Script].AsString(); + set => this.Set((int)SqlScriptTupleFields.Script, value); + } + + public string SqlDb_ + { + get => this.Fields[(int)SqlScriptTupleFields.SqlDb_].AsString(); + set => this.Set((int)SqlScriptTupleFields.SqlDb_, value); + } + + public string Component_ + { + get => this.Fields[(int)SqlScriptTupleFields.Component_].AsString(); + set => this.Set((int)SqlScriptTupleFields.Component_, value); + } + + public string ScriptBinary_ + { + get => this.Fields[(int)SqlScriptTupleFields.ScriptBinary_].AsString(); + set => this.Set((int)SqlScriptTupleFields.ScriptBinary_, value); + } + + public string User_ + { + get => this.Fields[(int)SqlScriptTupleFields.User_].AsString(); + set => this.Set((int)SqlScriptTupleFields.User_, value); + } + + public int Attributes + { + get => this.Fields[(int)SqlScriptTupleFields.Attributes].AsNumber(); + set => this.Set((int)SqlScriptTupleFields.Attributes, value); + } + + public int Sequence + { + get => this.Fields[(int)SqlScriptTupleFields.Sequence].AsNumber(); + set => this.Set((int)SqlScriptTupleFields.Sequence, value); + } + } +} \ No newline at end of file diff --git a/src/wixext/Tuples/SqlStringTuple.cs b/src/wixext/Tuples/SqlStringTuple.cs new file mode 100644 index 00000000..d2cba0e0 --- /dev/null +++ b/src/wixext/Tuples/SqlStringTuple.cs @@ -0,0 +1,95 @@ +// 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. + +namespace WixToolset.Sql +{ + using WixToolset.Data; + using WixToolset.Sql.Tuples; + + public static partial class SqlTupleDefinitions + { + public static readonly IntermediateTupleDefinition SqlString = new IntermediateTupleDefinition( + SqlTupleDefinitionType.SqlString.ToString(), + new[] + { + new IntermediateFieldDefinition(nameof(SqlStringTupleFields.String), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(SqlStringTupleFields.SqlDb_), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(SqlStringTupleFields.Component_), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(SqlStringTupleFields.SQL), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(SqlStringTupleFields.User_), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(SqlStringTupleFields.Attributes), IntermediateFieldType.Number), + new IntermediateFieldDefinition(nameof(SqlStringTupleFields.Sequence), IntermediateFieldType.Number), + }, + typeof(SqlStringTuple)); + } +} + +namespace WixToolset.Sql.Tuples +{ + using WixToolset.Data; + + public enum SqlStringTupleFields + { + String, + SqlDb_, + Component_, + SQL, + User_, + Attributes, + Sequence, + } + + public class SqlStringTuple : IntermediateTuple + { + public SqlStringTuple() : base(SqlTupleDefinitions.SqlString, null, null) + { + } + + public SqlStringTuple(SourceLineNumber sourceLineNumber, Identifier id = null) : base(SqlTupleDefinitions.SqlString, sourceLineNumber, id) + { + } + + public IntermediateField this[SqlStringTupleFields index] => this.Fields[(int)index]; + + public string String + { + get => this.Fields[(int)SqlStringTupleFields.String].AsString(); + set => this.Set((int)SqlStringTupleFields.String, value); + } + + public string SqlDb_ + { + get => this.Fields[(int)SqlStringTupleFields.SqlDb_].AsString(); + set => this.Set((int)SqlStringTupleFields.SqlDb_, value); + } + + public string Component_ + { + get => this.Fields[(int)SqlStringTupleFields.Component_].AsString(); + set => this.Set((int)SqlStringTupleFields.Component_, value); + } + + public string SQL + { + get => this.Fields[(int)SqlStringTupleFields.SQL].AsString(); + set => this.Set((int)SqlStringTupleFields.SQL, value); + } + + public string User_ + { + get => this.Fields[(int)SqlStringTupleFields.User_].AsString(); + set => this.Set((int)SqlStringTupleFields.User_, value); + } + + public int Attributes + { + get => this.Fields[(int)SqlStringTupleFields.Attributes].AsNumber(); + set => this.Set((int)SqlStringTupleFields.Attributes, value); + } + + public int Sequence + { + get => this.Fields[(int)SqlStringTupleFields.Sequence].AsNumber(); + set => this.Set((int)SqlStringTupleFields.Sequence, value); + } + } +} \ No newline at end of file diff --git a/src/wixext/Tuples/SqlTupleDefinitions.cs b/src/wixext/Tuples/SqlTupleDefinitions.cs new file mode 100644 index 00000000..b99b96a7 --- /dev/null +++ b/src/wixext/Tuples/SqlTupleDefinitions.cs @@ -0,0 +1,51 @@ +// 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. + +namespace WixToolset.Sql +{ + using System; + using WixToolset.Data; + + public enum SqlTupleDefinitionType + { + SqlDatabase, + SqlFileSpec, + SqlScript, + SqlString, + } + + public static partial class SqlTupleDefinitions + { + public static readonly Version Version = new Version("4.0.0"); + + public static IntermediateTupleDefinition ByName(string name) + { + if (!Enum.TryParse(name, out SqlTupleDefinitionType type)) + { + return null; + } + + return ByType(type); + } + + public static IntermediateTupleDefinition ByType(SqlTupleDefinitionType type) + { + switch (type) + { + case SqlTupleDefinitionType.SqlDatabase: + return SqlTupleDefinitions.SqlDatabase; + + case SqlTupleDefinitionType.SqlFileSpec: + return SqlTupleDefinitions.SqlFileSpec; + + case SqlTupleDefinitionType.SqlScript: + return SqlTupleDefinitions.SqlScript; + + case SqlTupleDefinitionType.SqlString: + return SqlTupleDefinitions.SqlString; + + default: + throw new ArgumentOutOfRangeException(nameof(type)); + } + } + } +} -- cgit v1.2.3-55-g6feb