diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2020-04-03 11:01:57 +1000 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2020-04-03 13:45:39 +1000 |
| commit | 9a128569f6ebf7ed43d57b0ecd4ada5ba8a5585a (patch) | |
| tree | 8ad278e97a67f77d178aef0b8c4781800286e260 /src | |
| parent | e9fb8cfde9cbd9f9f9f52957828b7993b9d9355a (diff) | |
| download | wix-9a128569f6ebf7ed43d57b0ecd4ada5ba8a5585a.tar.gz wix-9a128569f6ebf7ed43d57b0ecd4ada5ba8a5585a.tar.bz2 wix-9a128569f6ebf7ed43d57b0ecd4ada5ba8a5585a.zip | |
Add TupleIdIsPrimaryKey.
Diffstat (limited to 'src')
| -rw-r--r-- | src/WixToolset.Data/WindowsInstaller/TableDefinition.cs | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/src/WixToolset.Data/WindowsInstaller/TableDefinition.cs b/src/WixToolset.Data/WindowsInstaller/TableDefinition.cs index 527199b2..9740b89b 100644 --- a/src/WixToolset.Data/WindowsInstaller/TableDefinition.cs +++ b/src/WixToolset.Data/WindowsInstaller/TableDefinition.cs | |||
| @@ -24,12 +24,8 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 24 | /// <param name="name">Name of table to create.</param> | 24 | /// <param name="name">Name of table to create.</param> |
| 25 | /// <param name="columns">Column definitions for the table.</param> | 25 | /// <param name="columns">Column definitions for the table.</param> |
| 26 | /// <param name="unreal">Flag if table is unreal.</param> | 26 | /// <param name="unreal">Flag if table is unreal.</param> |
| 27 | public TableDefinition(string name, IEnumerable<ColumnDefinition> columns, bool unreal = false) | 27 | public TableDefinition(string name, IEnumerable<ColumnDefinition> columns, bool unreal = false) : this(name, null, columns, unreal) |
| 28 | { | 28 | { |
| 29 | this.Name = name; | ||
| 30 | this.TupleDefinitionName = name; | ||
| 31 | this.Unreal = unreal; | ||
| 32 | this.Columns = columns.ToArray(); | ||
| 33 | } | 29 | } |
| 34 | 30 | ||
| 35 | /// <summary> | 31 | /// <summary> |
| @@ -39,34 +35,49 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 39 | /// <param name="tupleDefinitionName">Optional name of tuple definition for this table.</param> | 35 | /// <param name="tupleDefinitionName">Optional name of tuple definition for this table.</param> |
| 40 | /// <param name="columns">Column definitions for the table.</param> | 36 | /// <param name="columns">Column definitions for the table.</param> |
| 41 | /// <param name="unreal">Flag if table is unreal.</param> | 37 | /// <param name="unreal">Flag if table is unreal.</param> |
| 42 | public TableDefinition(string name, string tupleDefinitionName, IEnumerable<ColumnDefinition> columns, bool unreal = false) : this(name, columns, unreal) | 38 | public TableDefinition(string name, string tupleDefinitionName, IEnumerable<ColumnDefinition> columns, bool unreal = false) |
| 43 | { | 39 | { |
| 40 | this.Name = name; | ||
| 44 | this.TupleDefinitionName = tupleDefinitionName ?? name; | 41 | this.TupleDefinitionName = tupleDefinitionName ?? name; |
| 42 | this.Unreal = unreal; | ||
| 43 | this.Columns = columns?.ToArray(); | ||
| 44 | |||
| 45 | if (this.Columns == null || this.Columns.Length == 0) | ||
| 46 | { | ||
| 47 | throw new ArgumentOutOfRangeException(nameof(columns)); | ||
| 48 | } | ||
| 49 | this.TupleIdIsPrimaryKey = DeriveTupleIdIsPrimaryKey(this.Columns); | ||
| 45 | } | 50 | } |
| 46 | 51 | ||
| 47 | /// <summary> | 52 | /// <summary> |
| 48 | /// Gets the name of the table. | 53 | /// Gets the name of the table. |
| 49 | /// </summary> | 54 | /// </summary> |
| 50 | /// <value>Name of the table.</value> | 55 | /// <value>Name of the table.</value> |
| 51 | public string Name { get; private set; } | 56 | public string Name { get; } |
| 52 | 57 | ||
| 53 | /// <summary> | 58 | /// <summary> |
| 54 | /// Gets the name of the tuple definition associated with this table. | 59 | /// Gets the name of the tuple definition associated with this table. |
| 55 | /// </summary> | 60 | /// </summary> |
| 56 | /// <value>Name of the tuple definition.</value> | 61 | /// <value>Name of the tuple definition.</value> |
| 57 | public string TupleDefinitionName { get; private set; } | 62 | public string TupleDefinitionName { get; } |
| 58 | 63 | ||
| 59 | /// <summary> | 64 | /// <summary> |
| 60 | /// Gets if the table is unreal. | 65 | /// Gets if the table is unreal. |
| 61 | /// </summary> | 66 | /// </summary> |
| 62 | /// <value>Flag if table is unreal.</value> | 67 | /// <value>Flag if table is unreal.</value> |
| 63 | public bool Unreal { get; private set; } | 68 | public bool Unreal { get; } |
| 64 | 69 | ||
| 65 | /// <summary> | 70 | /// <summary> |
| 66 | /// Gets the collection of column definitions for this table. | 71 | /// Gets the collection of column definitions for this table. |
| 67 | /// </summary> | 72 | /// </summary> |
| 68 | /// <value>Collection of column definitions for this table.</value> | 73 | /// <value>Collection of column definitions for this table.</value> |
| 69 | public ColumnDefinition[] Columns { get; private set; } | 74 | public ColumnDefinition[] Columns { get; } |
| 75 | |||
| 76 | /// <summary> | ||
| 77 | /// Gets if the primary key is the id of the tuple definition associated with this table. | ||
| 78 | /// </summary> | ||
| 79 | /// <value>Flag if table is unreal.</value> | ||
| 80 | public bool TupleIdIsPrimaryKey { get; } | ||
| 70 | 81 | ||
| 71 | /// <summary> | 82 | /// <summary> |
| 72 | /// Gets the column definition in the table by index. | 83 | /// Gets the column definition in the table by index. |
| @@ -223,5 +234,14 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 223 | 234 | ||
| 224 | writer.WriteEndElement(); | 235 | writer.WriteEndElement(); |
| 225 | } | 236 | } |
| 237 | |||
| 238 | private static bool DeriveTupleIdIsPrimaryKey(ColumnDefinition[] columns) | ||
| 239 | { | ||
| 240 | return columns[0].PrimaryKey && | ||
| 241 | columns[0].Type == ColumnType.String && | ||
| 242 | columns[0].Category == ColumnCategory.Identifier && | ||
| 243 | !columns[0].Name.EndsWith("_") && | ||
| 244 | (columns.Length == 1 || !columns.Skip(1).Any(t => t.PrimaryKey)); | ||
| 245 | } | ||
| 226 | } | 246 | } |
| 227 | } | 247 | } |
