Permalink
Browse files

adding cleanup code

  • Loading branch information...
1 parent 026ed5c commit 4e5b10e3990ed684d4e56c5029c26978ab6c9211 U-CIQDEV\tritter committed Dec 31, 2009
Showing with 34 additions and 4 deletions.
  1. +6 −2 MainWindow_LogicalActions.cs
  2. +28 −2 SQL Server/Queries.cs
@@ -1,4 +1,5 @@
using System;
+using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -36,8 +37,11 @@ private void RunTests(object sender, RoutedEventArgs e)
private void MainWin_Closed(object sender, EventArgs e)
{
- //TODO: Delete all stored procs that start with "sprockettestrun" + "_" + (MainWindow.CurrentProcess.Id | MainWindow.CurrentProcess.MachineName.GetHashCode()).ToString()
- //TODO: Delete all TemporaryFilesCreated
+ //TODO: Track server and database changes, because this will leave messes behind if you change servers and databases.
+ SQL.Queries.DeleteProcsBeginningWith("sprockettestrun" + "_" + (MainWindow.CurrentProcess.Id | MainWindow.CurrentProcess.MachineName.GetHashCode()).ToString(),
+ CurentContext.Server, CurentContext.Database);
+ for (int i = 0; i < TemporaryFilesCreated.Count; i++)
+ File.Delete(TemporaryFilesCreated[i]);
}
}
}
View
@@ -26,16 +26,42 @@ public static List<SQLParam> GetStoredProcParameters(string serverName, string d
conn.Open();
var results = cmd.ExecuteReader();
-
+
List<SQLParam> paramList = new List<SQLParam>(5);
while (results.Read())
paramList.Add(new SQLParam(results["name"].ToString(), results["type"].ToString()));
-
+
conn.Close();
return paramList;
}
+ public static void DeleteProcsBeginningWith(string beginsWith, string serverName, string database)
+ {
+ if (beginsWith.IsNullOrEmpty()) throw new WTFException();
+
+ var conn = Connections.GetConnection(serverName, database);
+ SqlCommand cmd = conn.CreateCommand();
+ cmd.CommandType = CommandType.Text;
+ cmd.CommandText = @"SELECT sp.name as name
+ FROM sys.procedures sp with (nolock)
+ WHERE sp.name LIKE @procName + '%'";
+ cmd.Parameters.AddWithValue("@procName", beginsWith);
+
+ conn.Open();
+ var results = cmd.ExecuteReader();
+
+ StringBuilder sb = new StringBuilder();
+ while (results.Read())
+ sb.Append("DELETE PROCEDURE ").Append(results["name"]).Append(";");
+
+ cmd = conn.CreateCommand();
+ cmd.CommandType = CommandType.Text;
+ cmd.CommandText = sb.ToString();
+
+ conn.Close();
+ }
+
public static void CreateStoredProcedure(string procText, string server, string database)
{
var conn = Connections.GetConnection(server, database);

0 comments on commit 4e5b10e

Please sign in to comment.