Skip to content

Commit

Permalink
Merge pull request #1 from naseif/main
Browse files Browse the repository at this point in the history
First implementation of OptimalDB
  • Loading branch information
stho32 authored Jul 17, 2022
2 parents 5d20ff0 + 3ce163e commit bbf4211
Show file tree
Hide file tree
Showing 11 changed files with 416 additions and 19 deletions.
5 changes: 0 additions & 5 deletions Source/optimalDb/optimalDb.BL/Class1.cs

This file was deleted.

28 changes: 28 additions & 0 deletions Source/optimalDb/optimalDb.BL/DatabaseConnection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using optimalDb.Interfaces;

namespace optimalDb.BL;
public class DatabaseConnection : IDatabaseConnection
{
public string Name { get; }
public string ConnectionString { get; }

public DatabaseConnection(string name, string connectionString)
{
Name = name;
ConnectionString = connectionString;
}
}


public class ViewPerformanceTestResult : IViewPerformanceTestResult
{
public string ViewName { get; }

public decimal DurationInSeconds { get; }

public ViewPerformanceTestResult(string viewName, decimal durationInSeconds)
{
ViewName = viewName;
DurationInSeconds = durationInSeconds;
}
}
4 changes: 4 additions & 0 deletions Source/optimalDb/optimalDb.BL/optimalDb.BL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\optimalDb.Interfaces\optimalDb.Interfaces.csproj" />
</ItemGroup>

</Project>
5 changes: 0 additions & 5 deletions Source/optimalDb/optimalDb.Interfaces/Class1.cs

This file was deleted.

12 changes: 12 additions & 0 deletions Source/optimalDb/optimalDb.Interfaces/IDatabaseConnection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace optimalDb.Interfaces;
public interface IDatabaseConnection
{
string Name { get; }
string ConnectionString { get; }
}

public interface IViewPerformanceTestResult
{
string ViewName { get; } // SCHEMA.VIEWNAME
decimal DurationInSeconds { get; } // 0.5s oder 30s ...
}
156 changes: 156 additions & 0 deletions Source/optimalDb/optimalDb.WinForms/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 96 additions & 0 deletions Source/optimalDb/optimalDb.WinForms/MainForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using optimalDb.BL;
using System.Data;
using System.Data.SqlClient;

namespace optimalDb.WinForms
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}

private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
var content = File.ReadAllText(openFileDialog1.FileName);
var connections = new List<DatabaseConnection>();
connections.Add(new DatabaseConnection("Naseif", "https:ASd234f233cv2fasdf"));
connections.Add(new DatabaseConnection("Stefan", "https:ASd234f233cv2fasdf"));

for (var i = 0; i < connections.Count; i++)
{
connectionsComboBox.Items.Add(connections[i].Name);
}


}
}

private void testButton_Click(object sender, EventArgs e)
{
DataTable alleViews;
var connectionString = "Server = .\\SQLEXPRESS; Database = AdventureWorks2019; Trusted_Connection = True;";
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();

var sql = @"
SELECT t.TABLE_SCHEMA, t.TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES t
WHERE t.TABLE_TYPE = 'VIEW'";

using (SqlCommand command = new SqlCommand(sql, connection))
{
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet dataset = new DataSet();
adapter.Fill(dataset);
alleViews = dataset.Tables[0];
}
}

var result = new List<ViewPerformanceTestResult>();
foreach(DataRow row in alleViews.Rows)
{
result.Add(
new ViewPerformanceTestResult(
row["TABLE_SCHEMA"].ToString() + "." + row["TABLE_NAME"].ToString(),
GetDurationOfViewExecution(row["TABLE_SCHEMA"].ToString() + "." + row["TABLE_NAME"].ToString())
));
}

dataGridView1.DataSource = result;
}

protected decimal GetDurationOfViewExecution(string viewName)
{
DateTime start = DateTime.Now;

try
{
var connectionString = "Server = .\\SQLEXPRESS; Database = AdventureWorks2019; Trusted_Connection = True;";
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();

var sql = @"SELECT * FROM " + viewName;

using (SqlCommand command = new SqlCommand(sql, connection))
{
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet dataset = new DataSet();
adapter.Fill(dataset);
}
}
}
catch (Exception ex)
{
return 999;
}

return (decimal)(DateTime.Now - start).TotalSeconds;
}
}
}
66 changes: 66 additions & 0 deletions Source/optimalDb/optimalDb.WinForms/MainForm.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>132, 17</value>
</metadata>
</root>
Loading

0 comments on commit bbf4211

Please sign in to comment.