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

Commit 3b69327

Browse files
committed
fix MySql + add more tests to SqlCurrency
1 parent 263744c commit 3b69327

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/ServiceStack.OrmLite.MySql/MySqlDialectProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public string GetColumnDefinition(FieldDefinition fieldDef)
209209
}
210210

211211
public override string SqlCurrency(string fieldOrValue, string currencySymbol) =>
212-
SqlConcat(new []{ "'" + currencySymbol + "'", "format(" + fieldOrValue + ",2)"});
212+
SqlConcat(new []{ "'" + currencySymbol + "'", "cast(" + fieldOrValue + " as decimal(15,2))" });
213213

214214
protected MySqlConnection Unwrap(IDbConnection db)
215215
{

tests/ServiceStack.OrmLite.Tests/SqlDialectTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public class Sqltest
1313

1414
public class SqlDialectTests : OrmLiteTestBase
1515
{
16+
//public SqlDialectTests() : base(Dialect.PostgreSql) {}
17+
1618
[Test]
1719
public void Does_concat_values()
1820
{
@@ -40,6 +42,15 @@ public void Does_format_currency()
4042
db.DropAndCreateTable<Sqltest>();
4143

4244
db.Insert(new Sqltest { Value = 12 });
45+
46+
var sqlCurrency = db.GetDialectProvider().SqlCurrency("12.3456");
47+
var result = db.Scalar<string>($"SELECT {sqlCurrency} from sqltest");
48+
Assert.That(result, Is.EqualTo("$12.35"));
49+
50+
sqlCurrency = db.GetDialectProvider().SqlCurrency("12.3456", "£");
51+
result = db.Scalar<string>($"SELECT {sqlCurrency} from sqltest");
52+
Assert.That(result, Is.EqualTo("£12.35"));
53+
4354
db.Insert(new Sqltest { Value = 12.3 });
4455
db.Insert(new Sqltest { Value = 12.34 });
4556
db.Insert(new Sqltest { Value = 12.345 });

0 commit comments

Comments
 (0)