aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Data/WindowsInstaller/TableDefinition.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Data/WindowsInstaller/TableDefinition.cs')
-rw-r--r--src/WixToolset.Data/WindowsInstaller/TableDefinition.cs33
1 files changed, 8 insertions, 25 deletions
diff --git a/src/WixToolset.Data/WindowsInstaller/TableDefinition.cs b/src/WixToolset.Data/WindowsInstaller/TableDefinition.cs
index 5a9d2f20..7c4a3e9d 100644
--- a/src/WixToolset.Data/WindowsInstaller/TableDefinition.cs
+++ b/src/WixToolset.Data/WindowsInstaller/TableDefinition.cs
@@ -22,14 +22,15 @@ namespace WixToolset.Data.WindowsInstaller
22 /// Creates a table definition. 22 /// Creates a table definition.
23 /// </summary> 23 /// </summary>
24 /// <param name="name">Name of table to create.</param> 24 /// <param name="name">Name of table to create.</param>
25 /// <param name="tupleDefinition">Optional tuple definition for this table.</param>
25 /// <param name="columns">Column definitions for the table.</param> 26 /// <param name="columns">Column definitions for the table.</param>
26 /// <param name="unreal">Flag if table is unreal.</param> 27 /// <param name="unreal">Flag if table is unreal.</param>
27 /// <param name="tupleDefinitionName">Optional name of tuple definition for this table.</param>
28 /// <param name="tupleIdIsPrimaryKey">Whether the primary key is the id of the tuple definition associated with this table.</param> 28 /// <param name="tupleIdIsPrimaryKey">Whether the primary key is the id of the tuple definition associated with this table.</param>
29 public TableDefinition(string name, IEnumerable<ColumnDefinition> columns, bool unreal = false, string tupleDefinitionName = null, bool? tupleIdIsPrimaryKey = null) 29 public TableDefinition(string name, IntermediateTupleDefinition tupleDefinition, IEnumerable<ColumnDefinition> columns, bool unreal = false, bool tupleIdIsPrimaryKey = false)
30 { 30 {
31 this.Name = name; 31 this.Name = name;
32 this.TupleDefinitionName = tupleDefinitionName ?? name; 32 this.TupleDefinition = tupleDefinition;
33 this.TupleIdIsPrimaryKey = tupleIdIsPrimaryKey;
33 this.Unreal = unreal; 34 this.Unreal = unreal;
34 this.Columns = columns?.ToArray(); 35 this.Columns = columns?.ToArray();
35 36
@@ -37,7 +38,6 @@ namespace WixToolset.Data.WindowsInstaller
37 { 38 {
38 throw new ArgumentOutOfRangeException(nameof(columns)); 39 throw new ArgumentOutOfRangeException(nameof(columns));
39 } 40 }
40 this.TupleIdIsPrimaryKey = tupleIdIsPrimaryKey ?? DeriveTupleIdIsPrimaryKey(this.Columns);
41 } 41 }
42 42
43 /// <summary> 43 /// <summary>
@@ -47,10 +47,10 @@ namespace WixToolset.Data.WindowsInstaller
47 public string Name { get; } 47 public string Name { get; }
48 48
49 /// <summary> 49 /// <summary>
50 /// Gets the name of the tuple definition associated with this table. 50 /// Gets the tuple definition associated with this table.
51 /// </summary> 51 /// </summary>
52 /// <value>Name of the tuple definition.</value> 52 /// <value>The tuple definition.</value>
53 public string TupleDefinitionName { get; } 53 public IntermediateTupleDefinition TupleDefinition { get; }
54 54
55 /// <summary> 55 /// <summary>
56 /// Gets if the table is unreal. 56 /// Gets if the table is unreal.
@@ -130,9 +130,7 @@ namespace WixToolset.Data.WindowsInstaller
130 { 130 {
131 var empty = reader.IsEmptyElement; 131 var empty = reader.IsEmptyElement;
132 string name = null; 132 string name = null;
133 string tupleDefinitionName = null;
134 var unreal = false; 133 var unreal = false;
135 bool? tupleIdIsPrimaryKey = null;
136 134
137 while (reader.MoveToNextAttribute()) 135 while (reader.MoveToNextAttribute())
138 { 136 {
@@ -141,12 +139,6 @@ namespace WixToolset.Data.WindowsInstaller
141 case "name": 139 case "name":
142 name = reader.Value; 140 name = reader.Value;
143 break; 141 break;
144 case "tupleDefinitionName":
145 tupleDefinitionName = reader.Value;
146 break;
147 case "tupleIdIsPrimaryKey":
148 tupleIdIsPrimaryKey = reader.Value.Equals("yes");
149 break;
150 case "unreal": 142 case "unreal":
151 unreal = reader.Value.Equals("yes"); 143 unreal = reader.Value.Equals("yes");
152 break; 144 break;
@@ -203,7 +195,7 @@ namespace WixToolset.Data.WindowsInstaller
203 } 195 }
204 } 196 }
205 197
206 return new TableDefinition(name, columns.ToArray(), unreal, tupleDefinitionName, tupleIdIsPrimaryKey); 198 return new TableDefinition(name, null, columns.ToArray(), unreal);
207 } 199 }
208 200
209 /// <summary> 201 /// <summary>
@@ -228,14 +220,5 @@ namespace WixToolset.Data.WindowsInstaller
228 220
229 writer.WriteEndElement(); 221 writer.WriteEndElement();
230 } 222 }
231
232 private static bool DeriveTupleIdIsPrimaryKey(ColumnDefinition[] columns)
233 {
234 return columns[0].PrimaryKey &&
235 columns[0].Type == ColumnType.String &&
236 columns[0].Category == ColumnCategory.Identifier &&
237 !columns[0].Name.EndsWith("_") &&
238 (columns.Length == 1 || !columns.Skip(1).Any(t => t.PrimaryKey));
239 }
240 } 223 }
241} 224}