21 December, 2009
0 Comments
0 categories
For deploying database content, we use database script files (TSQL *.sql). When the structure of the database changes, these script must be adjusted. To change the script I use a NUnit test, that looks like:
StringBuilder result = new StringBuilder(string.Empty); // Read the contents of the file string fileContents = File.ReadAllText(@"..\..\..\MyDatabaseProject\Contents\Customer.sql"); // Split in lines string[] lines = fileContents.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); // Loop lines foreach (string line in lines) { // Determine if line starts with if (line.StartsWith("insert into Customer ")) { // Adjust line string adjustedLine = line.Insert(76, "'"); adjustedLine = adjustedLine.Insert(81, "AA'"); adjustedLine = adjustedLine.Insert(85, "'"); adjustedLine = adjustedLine.Insert(90, "ZZ'"); // Add adjusted line to output result.AppendLine(adjustedLine); } else { // Add line to output result.AppendLine(line); } } Console.Write(result.ToString());
Tags: C#