Skip to content

Commit ca58452

Browse files
committed
fix(project): upgrade package versions and refactor code
Updated project files and refactored code for consistency and improved readability. - Upgraded `Microsoft.Extensions.ObjectPool`, `Microsoft.Extensions.Logging`, and `Microsoft.Extensions.Configuration` packages from `9.0.2` to `9.0.3` in `SQLHelper` and `TestApp`. - Changed loop variable from `x` to `X` in `RunChanges` and `RunCurrent` methods in `MassInsert.cs`. - Modified variable names to PascalCase in `Program.cs` and changed `using` statement for `SqlConnection` to `await using`. - Adjusted SQL command string in `Program.cs` to include additional fields and improved variable declaration style. - Updated `RemoveDuplicateCommands` method in `Batch.cs` for more concise syntax. - Upgraded `Microsoft.Extensions.Configuration.EnvironmentVariables` and `Microsoft.Extensions.Configuration.Json` packages from `9.0.2` to `9.0.3` in `SQLHelper.Tests.csproj`. Closes #123
1 parent 98f9efd commit ca58452

File tree

6 files changed

+26
-28
lines changed

6 files changed

+26
-28
lines changed

SQLHelper.SpeedTests/SQLHelper.SpeedTests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
@@ -8,7 +8,7 @@
88

99
<ItemGroup>
1010
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
11-
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="9.0.2" />
11+
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="9.0.3" />
1212
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
1313
<PackageReference Include="ZString" Version="2.6.0" />
1414
</ItemGroup>

SQLHelper.SpeedTests/Tests/MassInsert.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void Cleanup()
6060
public async Task RunChanges()
6161
{
6262
_ = Helper2.CreateBatch();
63-
for (var x = 0; x < Count; ++x)
63+
for (var X = 0; X < Count; ++X)
6464
{
6565
_ = Helper2.AddQuery(CommandType.Text,
6666
"INSERT INTO [SpeedTestDatabase].[dbo].[TestTable](StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue,TimeSpanValue) VALUES(@0,@1,@2,@3,@4,@5,@6,@7,@8)",
@@ -84,7 +84,7 @@ public async Task RunChanges()
8484
public async Task RunCurrent()
8585
{
8686
_ = Helper.CreateBatch();
87-
for (var x = 0; x < Count; ++x)
87+
for (var X = 0; X < Count; ++X)
8888
{
8989
_ = Helper.AddQuery(CommandType.Text,
9090
"INSERT INTO [SpeedTestDatabase].[dbo].[TestTable](StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue,TimeSpanValue) VALUES(@0,@1,@2,@3,@4,@5,@6,@7,@8)",

TestApp/Program.cs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal class Program
1313
{
1414
private static async Task Main(string[] args)
1515
{
16-
using (var listener = new SqlClientListener())
16+
using (var Listener = new SqlClientListener())
1717
{
1818
var Services = new ServiceCollection();
1919
_ = Services.AddCanisterModules(x => x.AddAssembly(typeof(Program).Assembly).RegisterSQLHelper());
@@ -150,15 +150,14 @@ ORDER BY(dm_ius.user_scans + dm_ius.user_lookups) DESC")
150150
Console.WriteLine(Results[3].ToString(x => x.ToString()));
151151
}
152152

153-
using (var listener = new SqlClientListener())
154-
{
155-
var connectionString = "Data Source=localhost;Initial Catalog=SereneCMS;Integrated Security=SSPI;Pooling=false;TrustServerCertificate=True";
153+
using var listener = new SqlClientListener();
154+
const string connectionString = "Data Source=localhost;Initial Catalog=SereneCMS;Integrated Security=SSPI;Pooling=false;TrustServerCertificate=True";
156155

157-
// Open a connection to the AdventureWorks database.
158-
using var connection = new SqlConnection(connectionString);
159-
connection.Open();
156+
// Open a connection to the AdventureWorks database.
157+
await using var connection = new SqlConnection(connectionString);
158+
connection.Open();
160159

161-
var sql = @"SELECT TOP 25
160+
const string sql = @"SELECT TOP 25
162161
o.name AS ObjectName
163162
, i.name AS IndexName
164163
, i.index_id AS IndexID
@@ -185,20 +184,19 @@ WHERE OBJECTPROPERTY(dm_ius.OBJECT_ID, 'IsUserTable') = 1
185184
AND i.is_unique_constraint = 0
186185
AND(dm_ius.user_scans + dm_ius.user_lookups) > dm_ius.user_seeks
187186
ORDER BY(dm_ius.user_scans + dm_ius.user_lookups) DESC";
188-
var command = new SqlCommand(sql, connection);
187+
var command = new SqlCommand(sql, connection);
189188

190-
// Perform a data operation on the server.
191-
SqlDataReader reader = command.ExecuteReader();
192-
try
189+
// Perform a data operation on the server.
190+
SqlDataReader reader = command.ExecuteReader();
191+
try
192+
{
193+
while (reader.Read())
193194
{
194-
while (reader.Read())
195-
{
196-
// Read the data.
197-
}
195+
// Read the data.
198196
}
199-
catch (Exception ex) { Console.WriteLine(ex.ToString()); }
200-
reader.Close();
201197
}
198+
catch (Exception ex) { Console.WriteLine(ex.ToString()); }
199+
reader.Close();
202200
}
203201
}
204202
}

TestApp/TestApp.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFrameworks>net8.0</TargetFrameworks>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.2" />
9+
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.3" />
1010
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
1111
</ItemGroup>
1212

src/SQLHelper.DB/HelperClasses/Batch.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ public IBatch Clear()
139139
/// <returns>This</returns>
140140
public IBatch RemoveDuplicateCommands()
141141
{
142-
Commands = Commands.Distinct().ToList();
143-
Headers = Headers.Distinct().ToList();
142+
Commands = [.. Commands.Distinct()];
143+
Headers = [.. Headers.Distinct()];
144144
return this;
145145
}
146146

test/SQLHelper.Tests/SQLHelper.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
</ItemGroup>
3737

3838
<ItemGroup>
39-
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.2" />
40-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.2" />
39+
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.3" />
40+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.3" />
4141
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
4242
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
4343
<PrivateAssets>all</PrivateAssets>

0 commit comments

Comments
 (0)