aboutsummaryrefslogtreecommitdiff
path: root/src/wixext/SqlCompiler.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/wixext/SqlCompiler.cs')
-rw-r--r--src/wixext/SqlCompiler.cs142
1 files changed, 79 insertions, 63 deletions
diff --git a/src/wixext/SqlCompiler.cs b/src/wixext/SqlCompiler.cs
index 3fb33993..22b533de 100644
--- a/src/wixext/SqlCompiler.cs
+++ b/src/wixext/SqlCompiler.cs
@@ -7,6 +7,7 @@ namespace WixToolset.Sql
7 using System.Xml.Linq; 7 using System.Xml.Linq;
8 using WixToolset.Data; 8 using WixToolset.Data;
9 using WixToolset.Extensibility; 9 using WixToolset.Extensibility;
10 using WixToolset.Sql.Tuples;
10 11
11 /// <summary> 12 /// <summary>
12 /// The compiler for the WiX Toolset SQL Server Extension. 13 /// The compiler for the WiX Toolset SQL Server Extension.
@@ -45,8 +46,8 @@ namespace WixToolset.Sql
45 switch (parentElement.Name.LocalName) 46 switch (parentElement.Name.LocalName)
46 { 47 {
47 case "Component": 48 case "Component":
48 string componentId = context["ComponentId"]; 49 var componentId = context["ComponentId"];
49 string directoryId = context["DirectoryId"]; 50 var directoryId = context["DirectoryId"];
50 51
51 switch (element.Name.LocalName) 52 switch (element.Name.LocalName)
52 { 53 {
@@ -92,7 +93,7 @@ namespace WixToolset.Sql
92 /// <param name="componentId">Identifier for parent component.</param> 93 /// <param name="componentId">Identifier for parent component.</param>
93 private void ParseSqlDatabaseElement(Intermediate intermediate, IntermediateSection section, XElement element, string componentId) 94 private void ParseSqlDatabaseElement(Intermediate intermediate, IntermediateSection section, XElement element, string componentId)
94 { 95 {
95 SourceLineNumber sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element); 96 var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element);
96 Identifier id = null; 97 Identifier id = null;
97 int attributes = 0; 98 int attributes = 0;
98 string database = null; 99 string database = null;
@@ -102,7 +103,7 @@ namespace WixToolset.Sql
102 string server = null; 103 string server = null;
103 string user = null; 104 string user = null;
104 105
105 foreach (XAttribute attrib in element.Attributes()) 106 foreach (var attrib in element.Attributes())
106 { 107 {
107 if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) 108 if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace)
108 { 109 {
@@ -230,7 +231,7 @@ namespace WixToolset.Sql
230 231
231 if (null == id) 232 if (null == id)
232 { 233 {
233 this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Id")); 234 id = this.ParseHelper.CreateIdentifier("sdb", componentId, server, database);
234 } 235 }
235 236
236 if (null == database) 237 if (null == database)
@@ -252,11 +253,11 @@ namespace WixToolset.Sql
252 this.Messaging.Write(SqlErrors.OneOfAttributesRequiredUnderComponent(sourceLineNumbers, element.Name.LocalName, "CreateOnInstall", "CreateOnUninstall", "DropOnInstall", "DropOnUninstall")); 253 this.Messaging.Write(SqlErrors.OneOfAttributesRequiredUnderComponent(sourceLineNumbers, element.Name.LocalName, "CreateOnInstall", "CreateOnUninstall", "DropOnInstall", "DropOnUninstall"));
253 } 254 }
254 255
255 foreach (XElement child in element.Elements()) 256 foreach (var child in element.Elements())
256 { 257 {
257 if (this.Namespace == child.Name.Namespace) 258 if (this.Namespace == child.Name.Namespace)
258 { 259 {
259 SourceLineNumber childSourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(child); 260 var childSourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(child);
260 switch (child.Name.LocalName) 261 switch (child.Name.LocalName)
261 { 262 {
262 case "SqlScript": 263 case "SqlScript":
@@ -285,7 +286,7 @@ namespace WixToolset.Sql
285 this.Messaging.Write(ErrorMessages.TooManyElements(sourceLineNumbers, element.Name.LocalName, child.Name.LocalName, 1)); 286 this.Messaging.Write(ErrorMessages.TooManyElements(sourceLineNumbers, element.Name.LocalName, child.Name.LocalName, 1));
286 } 287 }
287 288
288 fileSpec = this.ParseSqlFileSpecElement(intermediate, section, child); 289 fileSpec = this.ParseSqlFileSpecElement(intermediate, section, child, id?.Id);
289 break; 290 break;
290 case "SqlLogFileSpec": 291 case "SqlLogFileSpec":
291 if (null == componentId) 292 if (null == componentId)
@@ -297,7 +298,7 @@ namespace WixToolset.Sql
297 this.Messaging.Write(ErrorMessages.TooManyElements(sourceLineNumbers, element.Name.LocalName, child.Name.LocalName, 1)); 298 this.Messaging.Write(ErrorMessages.TooManyElements(sourceLineNumbers, element.Name.LocalName, child.Name.LocalName, 1));
298 } 299 }
299 300
300 logFileSpec = this.ParseSqlFileSpecElement(intermediate, section, child); 301 logFileSpec = this.ParseSqlFileSpecElement(intermediate, section, child, id?.Id);
301 break; 302 break;
302 default: 303 default:
303 this.ParseHelper.UnexpectedElement(element, child); 304 this.ParseHelper.UnexpectedElement(element, child);
@@ -313,23 +314,25 @@ namespace WixToolset.Sql
313 if (null != componentId) 314 if (null != componentId)
314 { 315 {
315 // Reference InstallSqlData and UninstallSqlData since nothing will happen without it 316 // Reference InstallSqlData and UninstallSqlData since nothing will happen without it
316 this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", "InstallSqlData"); 317 this.AddReferenceToInstallSqlData(section, sourceLineNumbers);
317 this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", "UninstallSqlData");
318 } 318 }
319 319
320 if (!this.Messaging.EncounteredError) 320 if (!this.Messaging.EncounteredError)
321 { 321 {
322 var row = this.ParseHelper.CreateRow(section, sourceLineNumbers, "SqlDatabase", id); 322 var tuple = section.AddTuple(new SqlDatabaseTuple(sourceLineNumbers, id)
323 row.Set(1, server); 323 {
324 row.Set(2, instance); 324 Server = server,
325 row.Set(3, database); 325 Instance = instance,
326 row.Set(4, componentId); 326 Database = database,
327 row.Set(5, user); 327 ComponentRef = componentId,
328 row.Set(6, fileSpec?.Id); 328 UserRef = user,
329 row.Set(7, logFileSpec?.Id); 329 FileSpecRef = fileSpec?.Id,
330 LogFileSpecRef = logFileSpec?.Id,
331 });
332
330 if (0 != attributes) 333 if (0 != attributes)
331 { 334 {
332 row.Set(8, attributes); 335 tuple.Attributes = attributes;
333 } 336 }
334 } 337 }
335 } 338 }
@@ -341,9 +344,9 @@ namespace WixToolset.Sql
341 /// <param name="section"></param> 344 /// <param name="section"></param>
342 /// <param name="element">Element to parse.</param> 345 /// <param name="element">Element to parse.</param>
343 /// <returns>Identifier of sql file specification.</returns> 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)
345 { 348 {
346 SourceLineNumber sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element); 349 var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element);
347 Identifier id = null; 350 Identifier id = null;
348 string fileName = null; 351 string fileName = null;
349 string growthSize = null; 352 string growthSize = null;
@@ -351,7 +354,7 @@ namespace WixToolset.Sql
351 string name = null; 354 string name = null;
352 string size = null; 355 string size = null;
353 356
354 foreach (XAttribute attrib in element.Attributes()) 357 foreach (var attrib in element.Attributes())
355 { 358 {
356 if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) 359 if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace)
357 { 360 {
@@ -388,7 +391,7 @@ namespace WixToolset.Sql
388 391
389 if (null == id) 392 if (null == id)
390 { 393 {
391 this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Id")); 394 id = this.ParseHelper.CreateIdentifier("sfs", parentId, name, fileName);
392 } 395 }
393 396
394 if (null == name) 397 if (null == name)
@@ -405,22 +408,25 @@ namespace WixToolset.Sql
405 408
406 if (!this.Messaging.EncounteredError) 409 if (!this.Messaging.EncounteredError)
407 { 410 {
408 var row = this.ParseHelper.CreateRow(section, sourceLineNumbers, "SqlFileSpec", id); 411 var tuple = section.AddTuple(new SqlFileSpecTuple(sourceLineNumbers, id)
409 row.Set(1, name); 412 {
410 row.Set(2, fileName); 413 Name = name,
414 Filename = fileName,
415 });
416
411 if (null != size) 417 if (null != size)
412 { 418 {
413 row.Set(3, size); 419 tuple.Size = size;
414 } 420 }
415 421
416 if (null != maxSize) 422 if (null != maxSize)
417 { 423 {
418 row.Set(4, maxSize); 424 tuple.MaxSize = maxSize;
419 } 425 }
420 426
421 if (null != growthSize) 427 if (null != growthSize)
422 { 428 {
423 row.Set(5, growthSize); 429 tuple.GrowthSize = growthSize;
424 } 430 }
425 } 431 }
426 432
@@ -435,16 +441,16 @@ namespace WixToolset.Sql
435 /// <param name="sqlDb">Optional database to execute script against.</param> 441 /// <param name="sqlDb">Optional database to execute script against.</param>
436 private void ParseSqlScriptElement(Intermediate intermediate, IntermediateSection section, XElement element, string componentId, string sqlDb) 442 private void ParseSqlScriptElement(Intermediate intermediate, IntermediateSection section, XElement element, string componentId, string sqlDb)
437 { 443 {
438 SourceLineNumber sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element); 444 var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element);
439 Identifier id = null; 445 Identifier id = null;
440 int attributes = 0; 446 int attributes = 0;
441 bool rollbackAttribute = false; 447 var rollbackAttribute = false;
442 bool nonRollbackAttribute = false; 448 var nonRollbackAttribute = false;
443 string binary = null; 449 string binary = null;
444 int sequence = CompilerConstants.IntegerNotSet; 450 var sequence = CompilerConstants.IntegerNotSet;
445 string user = null; 451 string user = null;
446 452
447 foreach (XAttribute attrib in element.Attributes()) 453 foreach (var attrib in element.Attributes())
448 { 454 {
449 if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) 455 if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace)
450 { 456 {
@@ -455,7 +461,7 @@ namespace WixToolset.Sql
455 break; 461 break;
456 case "BinaryKey": 462 case "BinaryKey":
457 binary = this.ParseHelper.GetAttributeIdentifierValue(sourceLineNumbers, attrib); 463 binary = this.ParseHelper.GetAttributeIdentifierValue(sourceLineNumbers, attrib);
458 this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "Binary", binary); 464 this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, TupleDefinitions.Binary, binary);
459 break; 465 break;
460 case "Sequence": 466 case "Sequence":
461 sequence = this.ParseHelper.GetAttributeIntegerValue(sourceLineNumbers, attrib, 1, short.MaxValue); 467 sequence = this.ParseHelper.GetAttributeIntegerValue(sourceLineNumbers, attrib, 1, short.MaxValue);
@@ -466,7 +472,7 @@ namespace WixToolset.Sql
466 this.Messaging.Write(ErrorMessages.IllegalAttributeWhenNested(sourceLineNumbers, element.Name.LocalName, attrib.Name.LocalName, element.Parent.Name.LocalName)); 472 this.Messaging.Write(ErrorMessages.IllegalAttributeWhenNested(sourceLineNumbers, element.Name.LocalName, attrib.Name.LocalName, element.Parent.Name.LocalName));
467 } 473 }
468 sqlDb = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); 474 sqlDb = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib);
469 this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "SqlDatabase", sqlDb); 475 this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, SqlTupleDefinitions.SqlDatabase, sqlDb);
470 break; 476 break;
471 case "User": 477 case "User":
472 user = this.ParseHelper.GetAttributeIdentifierValue(sourceLineNumbers, attrib); 478 user = this.ParseHelper.GetAttributeIdentifierValue(sourceLineNumbers, attrib);
@@ -568,7 +574,7 @@ namespace WixToolset.Sql
568 574
569 if (null == id) 575 if (null == id)
570 { 576 {
571 this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Id")); 577 id = this.ParseHelper.CreateIdentifier("ssc", componentId, binary, sqlDb);
572 } 578 }
573 579
574 if (null == binary) 580 if (null == binary)
@@ -589,20 +595,22 @@ namespace WixToolset.Sql
589 this.ParseHelper.ParseForExtensionElements(this.Context.Extensions, intermediate, section, element); 595 this.ParseHelper.ParseForExtensionElements(this.Context.Extensions, intermediate, section, element);
590 596
591 // Reference InstallSqlData and UninstallSqlData since nothing will happen without it 597 // Reference InstallSqlData and UninstallSqlData since nothing will happen without it
592 this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", "InstallSqlData"); 598 this.AddReferenceToInstallSqlData(section, sourceLineNumbers);
593 this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", "UninstallSqlData");
594 599
595 if (!this.Messaging.EncounteredError) 600 if (!this.Messaging.EncounteredError)
596 { 601 {
597 var row = this.ParseHelper.CreateRow(section, sourceLineNumbers, "SqlScript", id); 602 var tuple = section.AddTuple(new SqlScriptTuple(sourceLineNumbers, id)
598 row.Set(1, sqlDb); 603 {
599 row.Set(2, componentId); 604 SqlDbRef = sqlDb,
600 row.Set(3, binary); 605 ComponentRef = componentId,
601 row.Set(4, user); 606 ScriptBinaryRef = binary,
602 row.Set(5, attributes); 607 UserRef = user,
608 Attributes = attributes,
609 });
610
603 if (CompilerConstants.IntegerNotSet != sequence) 611 if (CompilerConstants.IntegerNotSet != sequence)
604 { 612 {
605 row.Set(6, sequence); 613 tuple.Sequence = sequence;
606 } 614 }
607 } 615 }
608 } 616 }
@@ -615,16 +623,16 @@ namespace WixToolset.Sql
615 /// <param name="sqlDb">Optional database to execute string against.</param> 623 /// <param name="sqlDb">Optional database to execute string against.</param>
616 private void ParseSqlStringElement(Intermediate intermediate, IntermediateSection section, XElement element, string componentId, string sqlDb) 624 private void ParseSqlStringElement(Intermediate intermediate, IntermediateSection section, XElement element, string componentId, string sqlDb)
617 { 625 {
618 SourceLineNumber sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element); 626 var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element);
619 Identifier id = null; 627 Identifier id = null;
620 int attributes = 0; 628 int attributes = 0;
621 bool rollbackAttribute = false; 629 var rollbackAttribute = false;
622 bool nonRollbackAttribute = false; 630 var nonRollbackAttribute = false;
623 int sequence = CompilerConstants.IntegerNotSet; 631 var sequence = CompilerConstants.IntegerNotSet;
624 string sql = null; 632 string sql = null;
625 string user = null; 633 string user = null;
626 634
627 foreach (XAttribute attrib in element.Attributes()) 635 foreach (var attrib in element.Attributes())
628 { 636 {
629 if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) 637 if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace)
630 { 638 {
@@ -727,7 +735,7 @@ namespace WixToolset.Sql
727 } 735 }
728 736
729 sqlDb = this.ParseHelper.GetAttributeIdentifierValue(sourceLineNumbers, attrib); 737 sqlDb = this.ParseHelper.GetAttributeIdentifierValue(sourceLineNumbers, attrib);
730 this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "SqlDatabase", sqlDb); 738 this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, SqlTupleDefinitions.SqlDatabase, sqlDb);
731 break; 739 break;
732 case "User": 740 case "User":
733 user = this.ParseHelper.GetAttributeIdentifierValue(sourceLineNumbers, attrib); 741 user = this.ParseHelper.GetAttributeIdentifierValue(sourceLineNumbers, attrib);
@@ -746,7 +754,7 @@ namespace WixToolset.Sql
746 754
747 if (null == id) 755 if (null == id)
748 { 756 {
749 this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Id")); 757 id = this.ParseHelper.CreateIdentifier("sst", componentId, sql, sqlDb);
750 } 758 }
751 759
752 if (null == sql) 760 if (null == sql)
@@ -767,22 +775,30 @@ namespace WixToolset.Sql
767 this.ParseHelper.ParseForExtensionElements(this.Context.Extensions, intermediate, section, element); 775 this.ParseHelper.ParseForExtensionElements(this.Context.Extensions, intermediate, section, element);
768 776
769 // Reference InstallSqlData and UninstallSqlData since nothing will happen without it 777 // Reference InstallSqlData and UninstallSqlData since nothing will happen without it
770 this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", "InstallSqlData"); 778 this.AddReferenceToInstallSqlData(section, sourceLineNumbers);
771 this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", "UninstallSqlData");
772 779
773 if (!this.Messaging.EncounteredError) 780 if (!this.Messaging.EncounteredError)
774 { 781 {
775 var row = this.ParseHelper.CreateRow(section, sourceLineNumbers, "SqlString", id); 782 var tuple = section.AddTuple(new SqlStringTuple(sourceLineNumbers, id)
776 row.Set(1, sqlDb); 783 {
777 row.Set(2, componentId); 784 SqlDbRef = sqlDb,
778 row.Set(3, sql); 785 ComponentRef = componentId,
779 row.Set(4, user); 786 SQL = sql,
780 row.Set(5, attributes); 787 UserRef = user,
788 Attributes = attributes,
789 });
790
781 if (CompilerConstants.IntegerNotSet != sequence) 791 if (CompilerConstants.IntegerNotSet != sequence)
782 { 792 {
783 row.Set(6, sequence); 793 tuple.Sequence = sequence;
784 } 794 }
785 } 795 }
786 } 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 }
787 } 803 }
788} 804}