@joebigelow / wix / commits / 4d4e7acb

Move Query method in Builder to its own class and make it public. Sort results. Skip tables that don't exist.

Move Query method in Builder to its own class and make it public. Sort results. Skip tables that don't exist.

Sean Hall committed Sep 30, 2019 at 13:02 UTC 4d4e7acb6255676337b0f4f0ee4d590ba31357b7
2 files changed +64 -48
src/WixBuildTools.TestSupport/Builder.cs
+2 -48
@@ -1,12 +1,10 @@
1 -// 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.
1 +// 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.
2
3 namespace WixBuildTools.TestSupport
4 {
5 using System;
6 using System.Collections.Generic;
7 using System.IO;
8 - using System.Text;
9 - using WixToolset.Dtf.WindowsInstaller;
8
9 public class Builder
10 {
@@ -62,52 +60,8 @@ namespace WixBuildTools.TestSupport
60
61 buildFunc(args.ToArray());
62
65 - return this.Query(outputPath, tables);
63 + return Query.QueryDatabase(outputPath, tables);
64 }
65 }
68 -
69 - private string[] Query(string path, string[] tables)
70 - {
71 - var results = new List<string>();
72 -
73 - if (tables?.Length > 0)
74 - {
75 - var sb = new StringBuilder();
76 - using (var db = new Database(path))
77 - {
78 - foreach (var table in tables)
79 - {
80 - using (var view = db.OpenView($"SELECT * FROM `{table}`"))
81 - {
82 - view.Execute();
83 -
84 - Record record;
85 - while ((record = view.Fetch()) != null)
86 - {
87 - sb.Clear();
88 - sb.AppendFormat("{0}:", table);
89 -
90 - using (record)
91 - {
92 - for (var i = 0; i < record.FieldCount; ++i)
93 - {
94 - if (i > 0)
95 - {
96 - sb.Append("\t");
97 - }
98 -
99 - sb.Append(record[i + 1]?.ToString());
100 - }
101 - }
102 -
103 - results.Add(sb.ToString());
104 - }
105 - }
106 - }
107 - }
108 - }
109 -
110 - return results.ToArray();
111 - }
66 }
67 }
src/WixBuildTools.TestSupport/Query.cs new
+62
@@ -0,0 +1,62 @@
1 +// 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.
2 +
3 +namespace WixBuildTools.TestSupport
4 +{
5 + using System;
6 + using System.Collections.Generic;
7 + using System.Text;
8 + using WixToolset.Dtf.WindowsInstaller;
9 +
10 + public class Query
11 + {
12 + public static string[] QueryDatabase(string path, string[] tables)
13 + {
14 + var results = new List<string>();
15 +
16 + if (tables?.Length > 0)
17 + {
18 + var sb = new StringBuilder();
19 + using (var db = new Database(path))
20 + {
21 + foreach (var table in tables)
22 + {
23 + if (!db.IsTablePersistent(table))
24 + {
25 + continue;
26 + }
27 +
28 + using (var view = db.OpenView($"SELECT * FROM `{table}`"))
29 + {
30 + view.Execute();
31 +
32 + Record record;
33 + while ((record = view.Fetch()) != null)
34 + {
35 + sb.Clear();
36 + sb.AppendFormat("{0}:", table);
37 +
38 + using (record)
39 + {
40 + for (var i = 0; i < record.FieldCount; ++i)
41 + {
42 + if (i > 0)
43 + {
44 + sb.Append("\t");
45 + }
46 +
47 + sb.Append(record[i + 1]?.ToString());
48 + }
49 + }
50 +
51 + results.Add(sb.ToString());
52 + }
53 + }
54 + }
55 + }
56 + }
57 +
58 + results.Sort();
59 + return results.ToArray();
60 + }
61 + }
62 +}