Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 538747d

Browse files
authored
Merge pull request #519 from xplicit/extend_addparam
Add optional parameters (scale, precision, size) to AddParam
2 parents 6025180 + e6fb419 commit 538747d

File tree

2 files changed

+66
-5
lines changed

2 files changed

+66
-5
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using NUnit.Framework;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace ServiceStack.OrmLite.SqlServerTests.Issues
10+
{
11+
[TestFixture]
12+
public class PrecisionAndScaleTests : OrmLiteTestBase
13+
{
14+
private const string DropProcedureSql = @"
15+
IF OBJECT_ID('spGetNumber') IS NOT NULL
16+
DROP PROCEDURE spGetNumber";
17+
18+
private const string CreateProcedureSql = @"
19+
CREATE PROCEDURE spGetNumber
20+
(
21+
@pNumber decimal(8,3) OUT
22+
)
23+
AS
24+
BEGIN
25+
SELECT @pNumber = 12345.678
26+
END";
27+
28+
[Test]
29+
public void Can_execute_stored_procedure_with_scale_precision_params_()
30+
{
31+
using (var db = OpenDbConnection())
32+
{
33+
db.ExecuteSql(DropProcedureSql);
34+
db.ExecuteSql(CreateProcedureSql);
35+
36+
var cmd = db.SqlProc("spGetNumber");
37+
38+
var pNumber = cmd.AddParam("pNumber", 1.0, direction: ParameterDirection.Output, precision: 8, scale: 3);
39+
40+
cmd.ExecuteNonQuery();
41+
42+
Assert.That(pNumber.Value, Is.EqualTo(12345.678));
43+
}
44+
}
45+
}
46+
}

src/ServiceStack.OrmLite/OrmLiteReadCommandExtensions.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -907,9 +907,12 @@ public static IDbDataParameter AddParam(this IDbCommand dbCmd,
907907
string name,
908908
object value = null,
909909
ParameterDirection direction = ParameterDirection.Input,
910-
DbType? dbType = null)
910+
DbType? dbType = null,
911+
byte? precision = null,
912+
byte? scale = null,
913+
int? size=null)
911914
{
912-
var p = dbCmd.CreateParam(name, value, direction, dbType);
915+
var p = dbCmd.CreateParam(name, value, direction, dbType, precision, scale, size);
913916
dbCmd.Parameters.Add(p);
914917
return p;
915918
}
@@ -918,7 +921,10 @@ public static IDbDataParameter CreateParam(this IDbCommand dbCmd,
918921
string name,
919922
object value = null,
920923
ParameterDirection direction = ParameterDirection.Input,
921-
DbType? dbType = null)
924+
DbType? dbType = null,
925+
byte? precision=null,
926+
byte? scale=null,
927+
int? size=null)
922928
{
923929
var p = dbCmd.CreateParameter();
924930
var dialectProvider = dbCmd.GetDialectProvider();
@@ -935,8 +941,17 @@ public static IDbDataParameter CreateParam(this IDbCommand dbCmd,
935941
}
936942

937943
if (dbType != null)
938-
p.DbType = dbType.Value;
939-
944+
p.DbType = dbType.Value;
945+
946+
if (precision != null)
947+
p.Precision = precision.Value;
948+
949+
if (scale != null)
950+
p.Scale = scale.Value;
951+
952+
if (size != null)
953+
p.Size = size.Value;
954+
940955
return p;
941956
}
942957

0 commit comments

Comments
 (0)