aboutsummaryrefslogtreecommitdiff
path: root/src/WixBuildTools.TestSupport/Query.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/WixBuildTools.TestSupport/Query.cs62
1 files changed, 62 insertions, 0 deletions
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
3namespace 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}