Skip to content

Commit 5c05833

Browse files
committed
Properly handle upcasting of numbers into BigInteger (#1074).
1 parent 2197f7a commit 5c05833

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/FirebirdSql.Data.FirebirdClient.Tests/FbInt128SupportTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ public async Task PassesValueCorrectly(BigInteger value)
8585
}
8686
}
8787

88+
[Test]
89+
public Task CanPassAsByte() => CanPassAsTypeHelper<byte>(6);
90+
[Test]
91+
public Task CanPassAsInt16() => CanPassAsTypeHelper<short>(6);
92+
[Test]
93+
public Task CanPassAsInt32() => CanPassAsTypeHelper<int>(6);
94+
[Test]
95+
public Task CanPassAsInt64() => CanPassAsTypeHelper<long>(6);
96+
8897
[Test]
8998
public async Task ReadsValueNullCorrectly()
9099
{
@@ -149,4 +158,14 @@ async Task CanReadAsTypeHelper<T>(T value, Func<FbDataReader, T> getter)
149158
}
150159
}
151160
}
161+
162+
async Task CanPassAsTypeHelper<T>(T value)
163+
{
164+
await using (var cmd = Connection.CreateCommand())
165+
{
166+
cmd.CommandText = "select cast(@value as int128) from rdb$database";
167+
cmd.Parameters.AddWithValue("value", value);
168+
Assert.DoesNotThrowAsync(cmd.ExecuteScalarAsync);
169+
}
170+
}
152171
}

src/FirebirdSql.Data.FirebirdClient/Common/DbValue.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,14 @@ public FbDecFloat GetDecFloat()
265265

266266
public BigInteger GetInt128()
267267
{
268-
return (BigInteger)_value;
268+
return _value switch
269+
{
270+
byte b => b,
271+
short s => s,
272+
int i => i,
273+
long l => l,
274+
_ => (BigInteger)_value,
275+
};
269276
}
270277

271278
public FbZonedDateTime GetZonedDateTime()

0 commit comments

Comments
 (0)