-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathAnnotations.cs
More file actions
55 lines (47 loc) · 1.74 KB
/
Copy pathAnnotations.cs
File metadata and controls
55 lines (47 loc) · 1.74 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
48
49
50
51
52
53
54
55
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Data.SqlClient;
using System.Transactions;
using System.Security;
using System.Text.RegularExpressions;
namespace tSQLtCLR
{
public class Annotations
{
public Annotations()
{
}
[SqlFunction(DataAccess = DataAccessKind.None, IsDeterministic = true, IsPrecise = true, TableDefinition = "AnnotationNo INT, Annotation NVARCHAR(MAX)", FillRowMethodName = "ProcessRowForGetAnnotationList")]
public static IEnumerable GetAnnotationList([SqlFacet(MaxSize = -1)] SqlString procedureText)
{
Dictionary<int, SqlString> annotations = new Dictionary<int, SqlString> { };
int annotationNo = 0;
var reader = new System.IO.StringReader(GetProcedureTextAsString(procedureText));
string line;
Regex rgx = new Regex(@"^\s*--\[@tSQLt:");
while ((line = reader.ReadLine()) != null)
{
if (rgx.IsMatch(line))
{
annotationNo++;
annotations.Add(annotationNo, line.Trim().Substring(2));
}
}
return annotations;
}
private static string GetProcedureTextAsString(SqlString procedureText)
{
return (procedureText.IsNull) ? "" : procedureText.Value;
}
private static void ProcessRowForGetAnnotationList(object row, out SqlInt32 AnnotationNo, out SqlString Annotation)
{
var keyValuePair = (KeyValuePair<int, SqlString>)row;
AnnotationNo = keyValuePair.Key;
Annotation = keyValuePair.Value;
}
}
}