Skip to content

Commit 8f29217

Browse files
committed
Implement IDbDataParameter. Fixes #465
1 parent 426c4af commit 8f29217

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/MySqlConnector/MySql.Data.MySqlClient/MySqlParameter.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace MySql.Data.MySqlClient
99
{
10-
public sealed class MySqlParameter : DbParameter
10+
public sealed class MySqlParameter : DbParameter, IDbDataParameter
1111
{
1212
public MySqlParameter()
1313
{
@@ -54,10 +54,8 @@ public MySqlParameter(string name, MySqlDbType mySqlDbType, int size, ParameterD
5454
Direction = direction;
5555
IsNullable = isNullable;
5656
#if NET45
57-
if (precision != 0)
58-
throw new PlatformNotSupportedException("'precision' parameter is not supported on .NET 4.5.");
59-
if (scale != 0)
60-
throw new PlatformNotSupportedException("'scale' parameter is not supported on .NET 4.5.");
57+
((IDbDataParameter) this).Precision = precision;
58+
((IDbDataParameter) this).Scale = scale;
6159
#else
6260
Precision = precision;
6361
Scale = scale;
@@ -105,7 +103,10 @@ public override ParameterDirection Direction
105103

106104
public override bool IsNullable { get; set; }
107105

108-
#if !NET45
106+
#if NET45
107+
byte IDbDataParameter.Precision { get; set; }
108+
byte IDbDataParameter.Scale { get; set; }
109+
#else
109110
public override byte Precision { get; set; }
110111
public override byte Scale { get; set; }
111112
#endif

tests/SideBySide/ParameterTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,5 +259,23 @@ public void ResetDbType()
259259
Assert.Equal(DbType.Double, parameter.DbType);
260260
Assert.Equal(MySqlDbType.Double, parameter.MySqlDbType);
261261
}
262+
263+
[Fact]
264+
public void Precision()
265+
{
266+
IDbCommand command = new MySqlCommand();
267+
IDbDataParameter parameter = command.CreateParameter();
268+
parameter.Precision = 11;
269+
Assert.Equal((byte) 11, parameter.Precision);
270+
}
271+
272+
[Fact]
273+
public void Scale()
274+
{
275+
IDbCommand command = new MySqlCommand();
276+
IDbDataParameter parameter = command.CreateParameter();
277+
parameter.Scale = 12;
278+
Assert.Equal((byte) 12, parameter.Scale);
279+
}
262280
}
263281
}

0 commit comments

Comments
 (0)