diff options
author | Sean Hall <r.sean.hall@gmail.com> | 2019-09-30 13:02:53 +1000 |
---|---|---|
committer | Sean Hall <r.sean.hall@gmail.com> | 2019-09-30 13:06:41 +1000 |
commit | 4d4e7acb6255676337b0f4f0ee4d590ba31357b7 (patch) | |
tree | edcb2f433d6a5b6b28e9dc5628ef58ea64ea8ade /src | |
parent | 6452eb0554b667318e9c2d11d3c957b57cd9d65b (diff) | |
download | wix-4d4e7acb6255676337b0f4f0ee4d590ba31357b7.tar.gz wix-4d4e7acb6255676337b0f4f0ee4d590ba31357b7.tar.bz2 wix-4d4e7acb6255676337b0f4f0ee4d590ba31357b7.zip |
Move Query method in Builder to its own class and make it public.
Sort results.
Skip tables that don't exist.
Diffstat (limited to 'src')
-rw-r--r-- | src/WixBuildTools.TestSupport/Builder.cs | 50 | ||||
-rw-r--r-- | src/WixBuildTools.TestSupport/Query.cs | 62 |
2 files changed, 64 insertions, 48 deletions
diff --git a/src/WixBuildTools.TestSupport/Builder.cs b/src/WixBuildTools.TestSupport/Builder.cs index 62439ff7..aae9681a 100644 --- a/src/WixBuildTools.TestSupport/Builder.cs +++ b/src/WixBuildTools.TestSupport/Builder.cs | |||
@@ -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 | 2 | ||
3 | namespace WixBuildTools.TestSupport | 3 | namespace WixBuildTools.TestSupport |
4 | { | 4 | { |
5 | using System; | 5 | using System; |
6 | using System.Collections.Generic; | 6 | using System.Collections.Generic; |
7 | using System.IO; | 7 | using System.IO; |
8 | using System.Text; | ||
9 | using WixToolset.Dtf.WindowsInstaller; | ||
10 | 8 | ||
11 | public class Builder | 9 | public class Builder |
12 | { | 10 | { |
@@ -62,52 +60,8 @@ namespace WixBuildTools.TestSupport | |||
62 | 60 | ||
63 | buildFunc(args.ToArray()); | 61 | buildFunc(args.ToArray()); |
64 | 62 | ||
65 | return this.Query(outputPath, tables); | 63 | return Query.QueryDatabase(outputPath, tables); |
66 | } | 64 | } |
67 | } | 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 | } | ||
112 | } | 66 | } |
113 | } | 67 | } |
diff --git a/src/WixBuildTools.TestSupport/Query.cs b/src/WixBuildTools.TestSupport/Query.cs new file mode 100644 index 00000000..a5883067 --- /dev/null +++ b/src/WixBuildTools.TestSupport/Query.cs | |||
@@ -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 | } | ||