Skip to content

Commit 70ed480

Browse files
author
jeffshumphreys@gmail.com
committed
New functions, notes, TODOs
Added the SQL to register your functions. Ideally it should be generated from the C# metadata. Hah! But, that script is necessary. If you've used some of the functions or types in COMPUTED columns or as column data types, you may have some issues with regenerating.
1 parent 5605903 commit 70ed480

File tree

9 files changed

+374
-2
lines changed

9 files changed

+374
-2
lines changed

ActiveDirectory.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace MySQLCLRFunctions
8+
{
9+
public static class ActiveDirectory
10+
{
11+
// TODO: Pull additional data right from ad rather than from cached tables. Need, for instance, service accounts, and computers.
12+
}
13+
}

Adaptors.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ namespace MySQLCLRFunctions
1515
{
1616
public static class Adaptors
1717
{
18+
/// <summary>
19+
///
20+
/// Converts a hex string to a VARBINARY string, I think.
21+
///
22+
/// </summary>
23+
/// <param name="InputAsHex"></param>
24+
/// <returns></returns>
1825
[SqlFunction(DataAccess = DataAccessKind.None, IsDeterministic = true, IsPrecise = true)]
1926
public static string VarBin2Hex(SqlBytes InputAsHex)
2027
{

Environmental.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,12 @@ public static int Beep(int frequencyHz, int durationMs)
3030
Console.Beep(frequencyHz, durationMs);
3131
return 0;
3232
}
33+
34+
// TODO: UpSince a date, humanize
35+
// TODO: Crashed?
36+
// TODO: Did SQL Server properly restart?
37+
// TODO: What account is SQL Server running as?
38+
// TODO: Mount points and their size
39+
3340
}
3441
}

Files.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections;
3+
using Microsoft.SqlServer.Server;
4+
using System.Data.SqlTypes;
5+
using System.Text.RegularExpressions;
6+
using System.Text;
7+
using System.Net.NetworkInformation;
8+
using System.Net;
9+
using System.Net.Sockets;
10+
using System.Linq;
11+
using System.IO;
12+
using System.Xml.Schema;
13+
using System.Runtime.Remoting.Messaging;
14+
15+
namespace MySQLCLRFunctions
16+
{
17+
public static class Files
18+
{
19+
/// <summary>
20+
///
21+
/// Need a way to copy off locked files into temp space so I can open them in SSMS scripts, alter them swapping out macros, and execute them.
22+
/// But if you have a file open in SSMS and it is part of a Project, it is locked for reading. Files opened outside of a solution/project don't get locked this way.
23+
///
24+
/// This also works great for Excel old style (xls) when someone leaves it open on their desktop but you need to load something.
25+
///
26+
/// </summary>
27+
/// <returns>temporary file is created within the user's temporary folder.</returns>
28+
[SqlFunction(DataAccess = DataAccessKind.None, IsDeterministic = true, IsPrecise = true)]
29+
public static string TempFilePath()
30+
{
31+
return Path.GetTempFileName();
32+
}
33+
34+
// TODO: FileWatcher
35+
// TODO: FileEventWatcher
36+
}
37+
}

MySQLCLRFunctions.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@
4343
<Reference Include="System.Xml" />
4444
</ItemGroup>
4545
<ItemGroup>
46+
<Compile Include="ActiveDirectory.cs" />
4647
<Compile Include="Adaptors.cs" />
4748
<Compile Include="Compares.cs" />
4849
<Compile Include="Environmental.cs" />
4950
<Compile Include="FileNameExtract.cs" />
51+
<Compile Include="Files.cs" />
5052
<Compile Include="Humanization.cs" />
5153
<Compile Include="NetworkCollect.cs" />
5254
<Compile Include="NetworkTest.cs" />

MySQLCLRFunctions.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ VisualStudioVersion = 16.0.29827.131
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MySQLCLRFunctions", "MySQLCLRFunctions.csproj", "{6AEAE0BF-82E7-4793-8E9D-E649ABD0A807}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestMySQLCLRFunctions", "..\TestMySQLCLRFunctions\TestMySQLCLRFunctions.csproj", "{A084D459-BEE6-46BB-BB2C-4756879B2599}"
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestMySQLCLRFunctions", "TestMySQLCLRFunctions\TestMySQLCLRFunctions.csproj", "{A084D459-BEE6-46BB-BB2C-4756879B2599}"
99
EndProject
1010
Global
1111
GlobalSection(SolutionConfigurationPlatforms) = preSolution

SQLCLR_Register.sql

Lines changed: 299 additions & 0 deletions
Large diffs are not rendered by default.

StringExtract.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ public static string RightOfAny(string input, string markers)
113113
return input.Substring(i + 1);
114114
}
115115

116+
/// <summary>
117+
///
118+
/// Client-specific. But a good sampling of how Active Directory data can be pulled.
119+
///
120+
/// </summary>
121+
/// <param name="FullName"></param>
122+
/// <returns></returns>
116123
[SqlFunction(DataAccess = DataAccessKind.None, IsDeterministic = true, IsPrecise = true)]
117124
public static SqlString GetFirstName(SqlString FullName)
118125
{

TestMySQLCLRFunctions/TestMySQLCLRFunctions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
<None Include="App.config" />
5151
</ItemGroup>
5252
<ItemGroup>
53-
<ProjectReference Include="..\MySQLCLRFunctions\MySQLCLRFunctions.csproj">
53+
<ProjectReference Include="..\MySQLCLRFunctions.csproj">
5454
<Project>{6aeae0bf-82e7-4793-8e9d-e649abd0a807}</Project>
5555
<Name>MySQLCLRFunctions</Name>
5656
</ProjectReference>

0 commit comments

Comments
 (0)