Skip to content

Commit b66f21e

Browse files
authored
Merge pull request #175 from eaglestorm/bugs/issue-173
Fixed support for outbound parameters for decimal and numeric types.
2 parents 3c9692f + de767d0 commit b66f21e

File tree

3 files changed

+131
-2
lines changed

3 files changed

+131
-2
lines changed

src/AdoNetCore.AseClient/Internal/FormatItem.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,17 @@ public static FormatItem CreateForParameter(AseParameter parameter, DbEnvironmen
9595
break;
9696
}
9797
}
98-
98+
9999
//fixup the FormatItem's length,scale,precision for decimals
100100
if (format.IsDecimalType)
101101
{
102-
if (parameter.SendableValue == DBNull.Value)
102+
if (parameter.IsOutput)
103+
{
104+
format.Precision = parameter.Precision;
105+
format.Scale = parameter.Scale;
106+
format.Length = 1;
107+
}
108+
else if (parameter.SendableValue == DBNull.Value)
103109
{
104110
format.Precision = 1;
105111
format.Scale = 0;
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System;
2+
using System.Data;
3+
using Dapper;
4+
using NUnit.Framework;
5+
6+
namespace AdoNetCore.AseClient.Tests.Integration
7+
{
8+
[TestFixture]
9+
[Category("basic")]
10+
public class OutboundParamProcedureTests
11+
{
12+
private readonly string _createProc = @"CREATE PROCEDURE dbo.sp_test_173(@TotalValue numeric(18,4) = 0 output)
13+
AS
14+
set @TotalValue = 2819.0444";
15+
private readonly string _dropProc = @"drop procedure [dbo].[sp_test_173]";
16+
17+
[SetUp]
18+
public void Setup()
19+
{
20+
using (var connection = new AseConnection(ConnectionStrings.Pooled))
21+
{
22+
connection.Execute(_createProc);
23+
}
24+
}
25+
26+
[Test]
27+
public void Simple_Procedure_ShouldExecute()
28+
{
29+
using (var connection = new AseConnection(ConnectionStrings.Pooled))
30+
{
31+
connection.Open();
32+
var cmd = connection.CreateCommand();
33+
cmd.CommandText = "sp_test_173";
34+
cmd.CommandType = CommandType.StoredProcedure;
35+
var total = new AseParameter()
36+
{
37+
ParameterName = "@TotalValue",
38+
AseDbType = AseDbType.Decimal,
39+
Direction = ParameterDirection.Output,
40+
Precision = 18,
41+
Scale = 4
42+
};
43+
cmd.Parameters.Add(total);
44+
var result = cmd.ExecuteNonQuery();
45+
Assert.AreEqual(2819.0444m,Convert.ToDecimal(total.SendableValue));
46+
}
47+
}
48+
49+
[TearDown]
50+
public void Teardown()
51+
{
52+
using (var connection = new AseConnection(ConnectionStrings.Pooled))
53+
{
54+
connection.Execute(_dropProc);
55+
}
56+
}
57+
}
58+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Data;
4+
using System.Data.Common;
5+
using AdoNetCore.AseClient.Tests.ConnectionProvider;
6+
using Dapper;
7+
using NUnit.Framework;
8+
9+
namespace AdoNetCore.AseClient.Tests.Integration.Query
10+
{
11+
[Category("basic")]
12+
#if NET_FRAMEWORK
13+
[TestFixture(typeof(SapConnectionProvider), Explicit = true, Reason = "SAP AseClient tests are run for compatibility purposes.")]
14+
#endif
15+
[TestFixture(typeof(CoreFxConnectionProvider))]
16+
public class NumericTests<T> where T : IConnectionProvider
17+
{
18+
private DbConnection GetConnection()
19+
{
20+
return Activator.CreateInstance<T>().GetConnection(ConnectionStrings.PooledUtf8);
21+
}
22+
23+
[SetUp]
24+
public void Setup()
25+
{
26+
using (var connection = GetConnection())
27+
{
28+
connection.Execute("create table [dbo].[decimal_test_table] (value decimal(18,4))");
29+
}
30+
}
31+
32+
[TearDown]
33+
public void TearDown()
34+
{
35+
using (var connection = GetConnection())
36+
{
37+
connection.Execute("drop table [dbo].[decimal_test_table]");
38+
}
39+
}
40+
41+
public static IEnumerable<TestCaseData> SelectNumeric_FromTable_Cases()
42+
{
43+
yield return new TestCaseData(1m);
44+
yield return new TestCaseData(2819.0444m);
45+
yield return new TestCaseData(12345678901234.9999m);
46+
yield return new TestCaseData(-12345678901234.9999m);
47+
}
48+
49+
[TestCaseSource(nameof(SelectNumeric_FromTable_Cases))]
50+
public void SelectNumeric_FromTable(decimal input)
51+
{
52+
using (var connection = GetConnection())
53+
{
54+
var p = new DynamicParameters();
55+
p.Add("@input", input, DbType.Decimal);
56+
connection.Execute("insert into [dbo].[decimal_test_table] (value) values (@input)", p);
57+
}
58+
59+
using (var connection = GetConnection())
60+
{
61+
Assert.AreEqual(input, connection.QuerySingle<decimal>("select top 1 value from [dbo].[decimal_test_table]"));
62+
}
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)