forked from OpenDBDiff/OpenDBDiff
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQLQueryFactory.cs
More file actions
47 lines (42 loc) · 1.55 KB
/
SQLQueryFactory.cs
File metadata and controls
47 lines (42 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OpenDBDiff.SqlServer.Schema.SQLQueries
{
public static class SQLQueryFactory
{
private static Dictionary<string, string> queries = new Dictionary<string, string>();
public static string Get(string queryFullName, Model.DatabaseInfo.SQLServerVersion version)
{
return Get($"{queryFullName}.{version}");
}
public static string Get(string queryClass)
{
var ns = typeof(SQLQueryFactory).Namespace;
var qualifiedQueryClass = string.Concat(ns, '.', queryClass);
if (queries.ContainsKey(qualifiedQueryClass))
{
return queries[qualifiedQueryClass];
}
else
{
string query = FetchQuery(qualifiedQueryClass);
queries.Add(qualifiedQueryClass, query);
return query;
}
}
private static string FetchQuery(string queryFullName)
{
string resourceName = queryFullName + ".sql";
using (System.IO.Stream stream = typeof(SQLQueryFactory).Assembly.GetManifestResourceStream(resourceName))
{
if (stream == null) throw new InvalidOperationException("The Query " + queryFullName + " cannot be found");
using (System.IO.StreamReader reader = new System.IO.StreamReader(stream))
{
return reader.ReadToEnd();
}
}
}
}
}