Skip to content

Commit d3f3f4b

Browse files
committed
feat: implement AddWithValue across all providers and stabilize CI tests
1 parent 27ef567 commit d3f3f4b

6 files changed

Lines changed: 48 additions & 4 deletions

File tree

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
<Authors>vkuttyp</Authors>
88
<PackageLicenseExpression>MIT</PackageLicenseExpression>
99
<RepositoryUrl>https://github.com/vkuttyp/CosmoSQLClient-Dotnet</RepositoryUrl>
10-
<Version>1.9.0</Version>
10+
<Version>1.9.1</Version>
1111
</PropertyGroup>
1212
</Project>

src/CosmoSQLClient.MsSql/MsSqlConnection.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public sealed record MsSqlConfiguration
3535

3636
public static MsSqlConfiguration Parse(string connectionString)
3737
{
38-
if (string.IsNullOrEmpty(connectionString)) return new MsSqlConfiguration { Host = "localhost", Database = "dummy" };
38+
if (string.IsNullOrWhiteSpace(connectionString)) return new MsSqlConfiguration { Host = "localhost", Database = "dummy", TrustServerCertificate = true };
3939
var dict = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
4040
foreach (var part in connectionString.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
4141
{
@@ -177,7 +177,10 @@ private async Task ConnectTdsAsync(CancellationToken ct)
177177
if (_config.Encrypt)
178178
{
179179
var tdsTls = new TdsTlsStream(_stream!);
180-
var ssl = new SslStream(tdsTls, true, (s, c, ch, err) => _config.TrustServerCertificate || err == SslPolicyErrors.None);
180+
var ssl = new SslStream(tdsTls, true, (s, c, ch, err) => {
181+
if (_config.TrustServerCertificate) return true;
182+
return err == SslPolicyErrors.None;
183+
});
181184
await ssl.AuthenticateAsClientAsync(_config.Host).ConfigureAwait(false);
182185
tdsTls.SwitchToPassthrough();
183186

src/CosmoSQLClient.MySql/MySqlCommand.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ public override int IndexOf(string parameterName)
5353
return -1;
5454
}
5555
public override void Insert(int index, object value) => _params.Insert(index, (MySqlParameter)value);
56+
57+
public MySqlParameter AddWithValue(string name, object? value)
58+
{
59+
var p = new MySqlParameter(name, value);
60+
_params.Add(p);
61+
return p;
62+
}
63+
5664
public override void Remove(object value) => _params.Remove((MySqlParameter)value);
5765
public override void RemoveAt(int index) => _params.RemoveAt(index);
5866
public override void RemoveAt(string parameterName) { int i = IndexOf(parameterName); if (i != -1) _params.RemoveAt(i); }

src/CosmoSQLClient.Postgres/PostgresParameter.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ public sealed class PostgresParameterCollection : DbParameterCollection
8383
public override System.Collections.IEnumerator GetEnumerator() => _params.GetEnumerator();
8484
public override int IndexOf(object value) => _params.IndexOf((PostgresParameter)value);
8585
public override int IndexOf(string parameterName) => GetIndex(parameterName);
86+
87+
public PostgresParameter AddWithValue(string name, object? value)
88+
{
89+
var p = new PostgresParameter(name, value);
90+
_params.Add(p);
91+
return p;
92+
}
93+
8694
public override void Insert(int index, object value) => _params.Insert(index, (PostgresParameter)value);
8795
public override void Remove(object value) => _params.Remove((PostgresParameter)value);
8896
public override void RemoveAt(int index) => _params.RemoveAt(index);

src/CosmoSQLClient.Sqlite/SqliteCommand.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ public override int IndexOf(string parameterName)
5353
return -1;
5454
}
5555
public override void Insert(int index, object value) => _params.Insert(index, (SqliteParameter)value);
56+
57+
public SqliteParameter AddWithValue(string name, object? value)
58+
{
59+
var p = new SqliteParameter(name, value);
60+
_params.Add(p);
61+
return p;
62+
}
63+
5664
public override void Remove(object value) => _params.Remove((SqliteParameter)value);
5765
public override void RemoveAt(int index) => _params.RemoveAt(index);
5866
public override void RemoveAt(string parameterName) { int i = IndexOf(parameterName); if (i != -1) _params.RemoveAt(i); }

tests/CosmoSQLClient.MsSql.Tests/AdoNetTests.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ private static bool ShouldSkip {
3939
}
4040
}
4141

42-
private static string ConnectionString => (EnvConn ?? "") + ";TrustServerCertificate=True";
42+
private static string ConnectionString => (EnvConn ?? "") + (string.IsNullOrEmpty(EnvConn) ? "" : ";TrustServerCertificate=True");
4343

4444
[Fact]
4545
public async Task StandardAdoNet_Flow_ShouldWork()
@@ -96,6 +96,23 @@ public async Task StandardAdoNet_Parameters_ShouldWork()
9696
Assert.Equal("Hello ADO.NET", result);
9797
}
9898

99+
[Fact]
100+
public async Task StandardAdoNet_AddWithValue_ShouldWork()
101+
{
102+
if (ShouldSkip) return;
103+
104+
using var conn = new MsSqlConnection(ConnectionString);
105+
await conn.OpenAsync();
106+
107+
using var cmd = new MsSqlCommand("SELECT @val AS Echo", conn);
108+
109+
// This is the method the user reported missing in some versions/providers
110+
cmd.Parameters.AddWithValue("@val", "Hello AddWithValue");
111+
112+
var result = await cmd.ExecuteScalarAsync();
113+
Assert.Equal("Hello AddWithValue", result);
114+
}
115+
99116
[Fact]
100117
public async Task StandardAdoNet_Transactions_ShouldWork()
101118
{

0 commit comments

Comments
 (0)