public void SaveTestRunToDb(Benchmark.TestRun testRun) { if (testRun.Benchmark.ConnectionSettings.DbProvider == null) { MessageBox.Show("Database connection is not set.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } else { DbProviders.DbProvider provider = testRun.Benchmark.ConnectionSettings.DbProvider; DbProviders.DbBenchmarkObjectWriter writer = provider.CreateBenchmarkObjectWriter(); try { if (writer == null) { throw new Exception("The selected provider does not support this operation."); } Cursor.Current = Cursors.WaitCursor; provider.Connect(); writer.WriteToDb(testRun); provider.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { Cursor.Current = Cursors.Default; } } }
public void Execute() { Cursor.Current = Cursors.WaitCursor; try { dbProvider.Connect(); string query = GetSelectedText(); DataTable table = dbProvider.ExecuteQuery(query); gridView.DataSource = table; } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { dbProvider.Close(); } Cursor.Current = Cursors.Default; }
private void Execute() { try { DbProviders.DbProvider db = benchmark.ConnectionSettings.DbProvider; db.Connect(); // Init script. if (runInitScript) { db.OnBeforeInitScript(); Benchmark.StatementList initScriptStatements = benchmark.InitScript.GetStatementList(db.Name); foreach (Benchmark.Statement statement in initScriptStatements.Statements) { if (interruptTesting) { testingThread = null; OnTestingEnded(); return; } string commandText = statement.CommandText; try { db.Execute(commandText); ExecutorMessage message = new ExecutorMessage(); message.Message = "Statement completed"; message.MessageType = ExecutorMessageType.Info; message.Statement = commandText; OnMessage(message); } catch (Exception ex) { ExecutorMessage message = new ExecutorMessage(); message.Message = GetAllExceptionMessages(ex); message.MessageType = ExecutorMessageType.Error; message.Statement = commandText; OnMessage(message); testingThread = null; OnTestingEnded(); return; } } db.OnAfterInitScript(); } try { foreach (Benchmark.TestGroup testGroup in benchmark.TestGroups) { if (interruptTesting) { testingThread = null; OnTestingEnded(); return; } if (stopTesting) { break; } bool activeTests = false; foreach (Benchmark.Test test in testGroup.Tests) { if (test.Active) { activeTests = true; break; } } if (activeTests) { foreach (Benchmark.Configuration configuration in testGroup.Configurations) { if (interruptTesting) { testingThread = null; OnTestingEnded(); return; } if (stopTesting) { break; } Benchmark.ConfigurationResult currentConfigurationResult = null; foreach (Benchmark.ConfigurationResult configurationResult in testRun.ConfigurationResults) { if (configurationResult.ConfigurationId == configuration.Id) { currentConfigurationResult = configurationResult; break; } } try { db.OnBeforeConfigurationInitScript(configuration); // Init script. currentConfigurationResult.InitScriptStarted = true; Benchmark.StatementList configurationInitScriptStatements = configuration.InitScript.GetStatementList(db.Name); foreach (Benchmark.Statement statement in configurationInitScriptStatements.Statements) { if (interruptTesting) { testingThread = null; OnTestingEnded(); return; } string commandText = statement.CommandText; try { db.Execute(commandText); ExecutorMessage message = new ExecutorMessage(); message.Message = "Statement completed"; message.MessageType = ExecutorMessageType.Info; message.Statement = commandText; OnMessage(message); } catch (Exception ex) { currentConfigurationResult.InitScriptErrorMessage = GetAllExceptionMessages(ex); ExecutorMessage message = new ExecutorMessage(); message.Message = GetAllExceptionMessages(ex); message.MessageType = ExecutorMessageType.Error; message.Statement = commandText; OnMessage(message); testingThread = null; OnTestingEnded(); return; } } currentConfigurationResult.InitScriptCompleted = true; db.OnAfterConfigurationInitScript(configuration); foreach (Benchmark.Test test in testGroup.Tests) { try { if (!test.Active) { continue; } if (interruptTesting) { testingThread = null; OnTestingEnded(); return; } if (stopTesting) { break; } foreach (Benchmark.TestResult testResult in testRun.TestResults) { if (testResult.TestId == test.Id && testResult.ConfigurationId == configuration.Id) { if (testResult is Benchmark.PlanEquivalenceTestResult planEquivalenceTestResult) { try { planEquivalenceTestResult.Started = true; HashSet <DbProviders.QueryPlan> distinctPlans = new HashSet <DbProviders.QueryPlan>(); planEquivalenceTestResult.SuccessfullyCompletedVariants = 0; Benchmark.PlanEquivalenceTest planEquivalenceTest = (Benchmark.PlanEquivalenceTest)test; List <DataTable> results = new List <DataTable>(); foreach (Benchmark.QueryVariantResult queryVariantResult in planEquivalenceTestResult.QueryVariantResults) { try { if (interruptTesting) { testingThread = null; OnTestingEnded(); return; } if (stopTesting) { break; } queryVariantResult.Started = true; List <TimeSpan> timeSpans = new List <TimeSpan>(); DbProviders.QueryStatistics lastStats = null; for (int i = 0; i < queryRuns; i++) { DbProviders.QueryStatistics stats = db.GetQueryStatistics(queryVariantResult.Query, compareResults); if (checkResultSizes && stats.ResultSize != queryVariantResult.ExpectedResultSize) { throw new Exception(string.Format("Unexpected result size ({0} instead of {1}).", stats.ResultSize, planEquivalenceTest.ExpectedResultSize)); } timeSpans.Add(stats.QueryProcessingTime); lastStats = stats; } queryVariantResult.QueryProcessingTime = ComputeAvgTimeSpan(timeSpans); queryVariantResult.ResultSize = lastStats.ResultSize; DbProviders.QueryPlan plan = db.GetQueryPlan(queryVariantResult.Query); queryVariantResult.QueryPlan = plan; if (compareResults) { results.Add(lastStats.Result); } //// TODO - remove. //planEquivalenceTest.ExpectedResultSize = stats.ResultSize; //break; if (!distinctPlans.Contains(plan)) { distinctPlans.Add(plan); } ExecutorMessage message = new ExecutorMessage(); message.Message = "Query executed"; message.MessageType = ExecutorMessageType.Info; message.Statement = queryVariantResult.Query; planEquivalenceTestResult.SuccessfullyCompletedVariants++; OnMessage(message); } catch (Exception ex) { queryVariantResult.ErrorMessage = GetAllExceptionMessages(ex); ExecutorMessage message = new ExecutorMessage(); message.Message = GetAllExceptionMessages(ex); message.MessageType = ExecutorMessageType.Error; message.Statement = queryVariantResult.Query; OnMessage(message); } queryVariantResult.Completed = true; } planEquivalenceTestResult.DistinctQueryPlans = distinctPlans.Count; planEquivalenceTestResult.Completed = true; if (compareResults) { if (!CheckResultsEquality(results)) { throw new Exception(string.Format("The query variants returned different results.")); } } ExecutorMessage messageCompleted = new ExecutorMessage(); messageCompleted.Message = string.Format("Test {0} completed.", planEquivalenceTestResult.TestName); messageCompleted.MessageType = ExecutorMessageType.Info; messageCompleted.Statement = string.Empty; OnMessage(messageCompleted); } catch (Exception ex) { planEquivalenceTestResult.ErrorMessage = GetAllExceptionMessages(ex); ExecutorMessage message = new ExecutorMessage(); message.Message = GetAllExceptionMessages(ex); message.MessageType = ExecutorMessageType.Error; message.Statement = string.Empty; OnMessage(message); } } } } } catch (Exception ex) { ExecutorMessage message = new ExecutorMessage(); message.Message = GetAllExceptionMessages(ex); message.MessageType = ExecutorMessageType.Error; message.Statement = string.Empty; OnMessage(message); } } db.OnBeforeConfigurationCleanUpScript(configuration); // Clean up script. currentConfigurationResult.CleanUpScriptStarted = true; Benchmark.StatementList configurationCleanUpScriptStatements = configuration.CleanUpScript.GetStatementList(db.Name); foreach (Benchmark.Statement statement in configurationCleanUpScriptStatements.Statements) { if (interruptTesting) { testingThread = null; OnTestingEnded(); return; } string commandText = statement.CommandText; try { db.Execute(commandText); ExecutorMessage message = new ExecutorMessage(); message.Message = "Statement completed"; message.MessageType = ExecutorMessageType.Info; message.Statement = commandText; OnMessage(message); } catch (Exception ex) { currentConfigurationResult.CleanUpScriptErrorMessage = GetAllExceptionMessages(ex); ExecutorMessage message = new ExecutorMessage(); message.Message = GetAllExceptionMessages(ex); message.MessageType = ExecutorMessageType.Error; message.Statement = commandText; OnMessage(message); testingThread = null; OnTestingEnded(); return; } } currentConfigurationResult.CleanUpScriptCompleted = true; db.OnAfterConfigurationCleanUpScript(configuration); } catch (Exception ex) { ExecutorMessage message = new ExecutorMessage(); message.Message = GetAllExceptionMessages(ex); message.MessageType = ExecutorMessageType.Error; message.Statement = string.Empty; OnMessage(message); } //// TODO - remove. //break; } } } } catch (Exception ex) { ExecutorMessage message = new ExecutorMessage(); message.Message = GetAllExceptionMessages(ex); message.MessageType = ExecutorMessageType.Error; message.Statement = string.Empty; OnMessage(message); } // Clean up script. if (runCleanUpScript) { db.OnBeforeCleanUpScript(); Benchmark.StatementList cleanUpScriptStatements = benchmark.CleanUpScript.GetStatementList(db.Name); foreach (Benchmark.Statement statement in cleanUpScriptStatements.Statements) { if (interruptTesting) { testingThread = null; OnTestingEnded(); return; } string commandText = statement.CommandText; try { db.Execute(commandText); ExecutorMessage message = new ExecutorMessage(); message.Message = "Statement completed"; message.MessageType = ExecutorMessageType.Info; message.Statement = commandText; OnMessage(message); } catch (Exception ex) { ExecutorMessage message = new ExecutorMessage(); message.Message = GetAllExceptionMessages(ex); message.MessageType = ExecutorMessageType.Error; message.Statement = commandText; OnMessage(message); testingThread = null; OnTestingEnded(); return; } } db.OnAfterCleanUpScript(); } db.Close(); } catch (Exception ex) { ExecutorMessage message = new ExecutorMessage(); message.Message = GetAllExceptionMessages(ex); message.MessageType = ExecutorMessageType.Error; message.Statement = string.Empty; OnMessage(message); } testingThread = null; OnTestingEnded(); if (!stopTesting) { // Zajisteni opakovaneho spusteni testu. currentLoop++; if (currentLoop < testLoops) { OnInvokeStartTesting(); } else { if (closeOnComplete) { OnInvokeClose(); } } } }