Skip to content

Commit 7607beb

Browse files
committed
Initial DECFLOAT support (and INT128).
1 parent 0a08eff commit 7607beb

File tree

21 files changed

+1456
-59
lines changed

21 files changed

+1456
-59
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
* The contents of this file are subject to the Initial
3+
* Developer's Public License Version 1.0 (the "License");
4+
* you may not use this file except in compliance with the
5+
* License. You may obtain a copy of the License at
6+
* https://github.com/FirebirdSQL/NETProvider/blob/master/license.txt.
7+
*
8+
* Software distributed under the License is distributed on
9+
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
10+
* express or implied. See the License for the specific
11+
* language governing rights and limitations under the License.
12+
*
13+
* All Rights Reserved.
14+
*/
15+
16+
//$Authors = Jiri Cincura (jiri@cincura.net)
17+
18+
using System;
19+
using System.Numerics;
20+
using FirebirdSql.Data.TestsBase;
21+
using FirebirdSql.Data.Types;
22+
using NUnit.Framework;
23+
24+
namespace FirebirdSql.Data.FirebirdClient.Tests
25+
{
26+
[TestFixtureSource(typeof(FbDefaultServerTypeTestFixtureSource))]
27+
[TestFixtureSource(typeof(FbEmbeddedServerTypeTestFixtureSource))]
28+
public class FbDecFloat16SupportTests : FbTestsBase
29+
{
30+
public FbDecFloat16SupportTests(FbServerType serverType, bool compression, FbWireCrypt wireCrypt)
31+
: base(serverType, compression, wireCrypt)
32+
{ }
33+
34+
[SetUp]
35+
public override void SetUp()
36+
{
37+
base.SetUp();
38+
39+
if (!EnsureVersion(new Version(4, 0, 0, 0)))
40+
return;
41+
}
42+
43+
static readonly object[] TestValues = new[]
44+
{
45+
new object[] { (FbDecFloat)0, "0" },
46+
new object[] { (FbDecFloat)1, "1" },
47+
new object[] { (FbDecFloat)(-1), "-1" },
48+
new object[] { (FbDecFloat)6, "6" },
49+
new object[] { (FbDecFloat)(-6), "-6" },
50+
new object[] { FbDecFloat.NegativeZero, "-0" },
51+
new object[] { FbDecFloat.PositiveInfinity, "inf" },
52+
new object[] { FbDecFloat.NegativeInfinity, "-inf" },
53+
new object[] { FbDecFloat.PositiveNaN, "nan" },
54+
new object[] { FbDecFloat.NegativeNaN, "-nan" },
55+
new object[] { FbDecFloat.PositiveSignalingNaN, "snan" },
56+
new object[] { FbDecFloat.NegativeSignalingNaN, "-snan" },
57+
new object[] { (FbDecFloat)0.1, "0.1" },
58+
new object[] { (FbDecFloat)(-0.1), "-0.1" },
59+
new object[] { (FbDecFloat)6.6, "6.6" },
60+
new object[] { (FbDecFloat)(-6.6), "-6.6" },
61+
new object[] { new FbDecFloat(10, 34), "100000000000000000000000000000000000" },
62+
new object[] { new FbDecFloat(-10, 34), "-100000000000000000000000000000000000" },
63+
new object[] { new FbDecFloat(BigInteger.Parse("123000000001"), -10), "123.000000001E-1" },
64+
new object[] { new FbDecFloat(BigInteger.Parse("-123000000001"), -10), "-123.000000001E-1" },
65+
};
66+
67+
[TestCaseSource(nameof(TestValues))]
68+
public void ReadsValueCorrectly(FbDecFloat value, string castValue)
69+
{
70+
using (var cmd = Connection.CreateCommand())
71+
{
72+
cmd.CommandText = $"select cast('{castValue}' as decfloat(16)) from rdb$database";
73+
var result = (FbDecFloat)cmd.ExecuteScalar();
74+
Assert.AreEqual(value, result);
75+
}
76+
}
77+
78+
[TestCaseSource(nameof(TestValues))]
79+
public void PassesValueCorrectly(FbDecFloat value, string dummy)
80+
{
81+
using (var cmd = Connection.CreateCommand())
82+
{
83+
cmd.CommandText = "select cast(@value as decfloat(16)) from rdb$database";
84+
cmd.Parameters.AddWithValue("value", value);
85+
var result = (FbDecFloat)cmd.ExecuteScalar();
86+
Assert.AreEqual(value, result);
87+
}
88+
}
89+
90+
[Test]
91+
public void ReadsValueNullCorrectly()
92+
{
93+
using (var cmd = Connection.CreateCommand())
94+
{
95+
cmd.CommandText = "select cast(null as decfloat(16)) from rdb$database";
96+
var result = (DBNull)cmd.ExecuteScalar();
97+
Assert.AreEqual(DBNull.Value, result);
98+
}
99+
}
100+
101+
[Test]
102+
public void PassesValueNullCorrectly()
103+
{
104+
using (var cmd = Connection.CreateCommand())
105+
{
106+
cmd.CommandText = "select cast(@value as decfloat(16)) from rdb$database";
107+
cmd.Parameters.AddWithValue("value", DBNull.Value);
108+
var result = (DBNull)cmd.ExecuteScalar();
109+
Assert.AreEqual(DBNull.Value, result);
110+
}
111+
}
112+
113+
[Test]
114+
public void SimpleSelectSchemaTableTest()
115+
{
116+
using (var cmd = Connection.CreateCommand())
117+
{
118+
cmd.CommandText = "select cast(null as decfloat(16)) from rdb$database";
119+
using (var reader = cmd.ExecuteReader())
120+
{
121+
var schema = reader.GetSchemaTable();
122+
Assert.AreEqual(typeof(FbDecFloat), schema.Rows[0].ItemArray[5]);
123+
}
124+
}
125+
}
126+
}
127+
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
* The contents of this file are subject to the Initial
3+
* Developer's Public License Version 1.0 (the "License");
4+
* you may not use this file except in compliance with the
5+
* License. You may obtain a copy of the License at
6+
* https://github.com/FirebirdSQL/NETProvider/blob/master/license.txt.
7+
*
8+
* Software distributed under the License is distributed on
9+
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
10+
* express or implied. See the License for the specific
11+
* language governing rights and limitations under the License.
12+
*
13+
* All Rights Reserved.
14+
*/
15+
16+
//$Authors = Jiri Cincura (jiri@cincura.net)
17+
18+
using System;
19+
using System.Numerics;
20+
using FirebirdSql.Data.TestsBase;
21+
using FirebirdSql.Data.Types;
22+
using NUnit.Framework;
23+
24+
namespace FirebirdSql.Data.FirebirdClient.Tests
25+
{
26+
[TestFixtureSource(typeof(FbDefaultServerTypeTestFixtureSource))]
27+
[TestFixtureSource(typeof(FbEmbeddedServerTypeTestFixtureSource))]
28+
public class FbDecFloat34SupportTests : FbTestsBase
29+
{
30+
public FbDecFloat34SupportTests(FbServerType serverType, bool compression, FbWireCrypt wireCrypt)
31+
: base(serverType, compression, wireCrypt)
32+
{ }
33+
34+
[SetUp]
35+
public override void SetUp()
36+
{
37+
base.SetUp();
38+
39+
if (!EnsureVersion(new Version(4, 0, 0, 0)))
40+
return;
41+
}
42+
43+
static readonly object[] TestValues = new[]
44+
{
45+
new object[] { (FbDecFloat)0, "0" },
46+
new object[] { (FbDecFloat)1, "1" },
47+
new object[] { (FbDecFloat)(-1), "-1" },
48+
new object[] { (FbDecFloat)6, "6" },
49+
new object[] { (FbDecFloat)(-6), "-6" },
50+
new object[] { FbDecFloat.NegativeZero, "-0" },
51+
new object[] { FbDecFloat.PositiveInfinity, "inf" },
52+
new object[] { FbDecFloat.NegativeInfinity, "-inf" },
53+
new object[] { FbDecFloat.PositiveNaN, "nan" },
54+
new object[] { FbDecFloat.NegativeNaN, "-nan" },
55+
new object[] { FbDecFloat.PositiveSignalingNaN, "snan" },
56+
new object[] { FbDecFloat.NegativeSignalingNaN, "-snan" },
57+
new object[] { (FbDecFloat)0.1, "0.1" },
58+
new object[] { (FbDecFloat)(-0.1), "-0.1" },
59+
new object[] { (FbDecFloat)6.6, "6.6" },
60+
new object[] { (FbDecFloat)(-6.6), "-6.6" },
61+
new object[] { new FbDecFloat(10, 34), "100000000000000000000000000000000000" },
62+
new object[] { new FbDecFloat(-10, 34), "-100000000000000000000000000000000000" },
63+
new object[] { new FbDecFloat(BigInteger.Parse("123000000001"), -10), "123.000000001E-1" },
64+
new object[] { new FbDecFloat(BigInteger.Parse("-123000000001"), -10), "-123.000000001E-1" },
65+
};
66+
67+
[TestCaseSource(nameof(TestValues))]
68+
public void ReadsValueCorrectly(FbDecFloat value, string castValue)
69+
{
70+
using (var cmd = Connection.CreateCommand())
71+
{
72+
cmd.CommandText = $"select cast('{castValue}' as decfloat(34)) from rdb$database";
73+
var result = (FbDecFloat)cmd.ExecuteScalar();
74+
Assert.AreEqual(value, result);
75+
}
76+
}
77+
78+
[TestCaseSource(nameof(TestValues))]
79+
public void PassesValueCorrectly(FbDecFloat value, string dummy)
80+
{
81+
using (var cmd = Connection.CreateCommand())
82+
{
83+
cmd.CommandText = "select cast(@value as decfloat(34)) from rdb$database";
84+
cmd.Parameters.AddWithValue("value", value);
85+
var result = (FbDecFloat)cmd.ExecuteScalar();
86+
Assert.AreEqual(value, result);
87+
}
88+
}
89+
90+
[Test]
91+
public void ReadsValueNullCorrectly()
92+
{
93+
using (var cmd = Connection.CreateCommand())
94+
{
95+
cmd.CommandText = "select cast(null as decfloat(34)) from rdb$database";
96+
var result = (DBNull)cmd.ExecuteScalar();
97+
Assert.AreEqual(DBNull.Value, result);
98+
}
99+
}
100+
101+
[Test]
102+
public void PassesValueNullCorrectly()
103+
{
104+
using (var cmd = Connection.CreateCommand())
105+
{
106+
cmd.CommandText = "select cast(@value as decfloat(34)) from rdb$database";
107+
cmd.Parameters.AddWithValue("value", DBNull.Value);
108+
var result = (DBNull)cmd.ExecuteScalar();
109+
Assert.AreEqual(DBNull.Value, result);
110+
}
111+
}
112+
113+
[Test]
114+
public void SimpleSelectSchemaTableTest()
115+
{
116+
using (var cmd = Connection.CreateCommand())
117+
{
118+
cmd.CommandText = "select cast(null as decfloat(34)) from rdb$database";
119+
using (var reader = cmd.ExecuteReader())
120+
{
121+
var schema = reader.GetSchemaTable();
122+
Assert.AreEqual(typeof(FbDecFloat), schema.Rows[0].ItemArray[5]);
123+
}
124+
}
125+
}
126+
}
127+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* The contents of this file are subject to the Initial
3+
* Developer's Public License Version 1.0 (the "License");
4+
* you may not use this file except in compliance with the
5+
* License. You may obtain a copy of the License at
6+
* https://github.com/FirebirdSQL/NETProvider/blob/master/license.txt.
7+
*
8+
* Software distributed under the License is distributed on
9+
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
10+
* express or implied. See the License for the specific
11+
* language governing rights and limitations under the License.
12+
*
13+
* All Rights Reserved.
14+
*/
15+
16+
//$Authors = Jiri Cincura (jiri@cincura.net)
17+
18+
using System;
19+
using System.Numerics;
20+
using FirebirdSql.Data.TestsBase;
21+
using NUnit.Framework;
22+
23+
namespace FirebirdSql.Data.FirebirdClient.Tests
24+
{
25+
[TestFixtureSource(typeof(FbDefaultServerTypeTestFixtureSource))]
26+
[TestFixtureSource(typeof(FbEmbeddedServerTypeTestFixtureSource))]
27+
public class FbInt128SupportTests : FbTestsBase
28+
{
29+
public FbInt128SupportTests(FbServerType serverType, bool compression, FbWireCrypt wireCrypt)
30+
: base(serverType, compression, wireCrypt)
31+
{ }
32+
33+
[SetUp]
34+
public override void SetUp()
35+
{
36+
base.SetUp();
37+
38+
if (!EnsureVersion(new Version(4, 0, 0, 0)))
39+
return;
40+
}
41+
42+
static readonly BigInteger[] TestValues = new[]
43+
{
44+
BigInteger.Parse("0"),
45+
BigInteger.Parse("1"),
46+
BigInteger.Parse("-1"),
47+
BigInteger.Parse("6"),
48+
BigInteger.Parse("-6"),
49+
BigInteger.Parse("184467440737095516190874"),
50+
BigInteger.Parse("-184467440737095516190874"),
51+
};
52+
53+
[TestCaseSource(nameof(TestValues))]
54+
public void ReadsValueCorrectly(BigInteger value)
55+
{
56+
using (var cmd = Connection.CreateCommand())
57+
{
58+
cmd.CommandText = $"select cast({value} as int128) from rdb$database";
59+
var result = (BigInteger)cmd.ExecuteScalar();
60+
Assert.AreEqual(value, result);
61+
}
62+
}
63+
64+
[TestCaseSource(nameof(TestValues))]
65+
public void PassesValueCorrectly(BigInteger value)
66+
{
67+
using (var cmd = Connection.CreateCommand())
68+
{
69+
cmd.CommandText = "select cast(@value as int128) from rdb$database";
70+
cmd.Parameters.AddWithValue("value", value);
71+
var result = (BigInteger)cmd.ExecuteScalar();
72+
Assert.AreEqual(value, result);
73+
}
74+
}
75+
76+
[Test]
77+
public void ReadsValueNullCorrectly()
78+
{
79+
using (var cmd = Connection.CreateCommand())
80+
{
81+
cmd.CommandText = "select cast(null as int128) from rdb$database";
82+
var result = (DBNull)cmd.ExecuteScalar();
83+
Assert.AreEqual(DBNull.Value, result);
84+
}
85+
}
86+
87+
[Test]
88+
public void PassesValueNullCorrectly()
89+
{
90+
using (var cmd = Connection.CreateCommand())
91+
{
92+
cmd.CommandText = "select cast(@value as int128) from rdb$database";
93+
cmd.Parameters.AddWithValue("value", DBNull.Value);
94+
var result = (DBNull)cmd.ExecuteScalar();
95+
Assert.AreEqual(DBNull.Value, result);
96+
}
97+
}
98+
99+
[Test]
100+
public void SimpleSelectSchemaTableTest()
101+
{
102+
using (var cmd = Connection.CreateCommand())
103+
{
104+
cmd.CommandText = "select cast(null as int128) from rdb$database";
105+
using (var reader = cmd.ExecuteReader())
106+
{
107+
var schema = reader.GetSchemaTable();
108+
Assert.AreEqual(typeof(BigInteger), schema.Rows[0].ItemArray[5]);
109+
}
110+
}
111+
}
112+
}
113+
}

Provider/src/FirebirdSql.Data.FirebirdClient/Client/Managed/IXdrReader.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
//$Authors = Jiri Cincura (jiri@cincura.net)
1717

1818
using System;
19+
using System.Numerics;
1920
using System.Threading.Tasks;
2021
using FirebirdSql.Data.Common;
22+
using FirebirdSql.Data.Types;
2123

2224
namespace FirebirdSql.Data.Client.Managed
2325
{
@@ -43,6 +45,11 @@ interface IXdrReader
4345
TimeSpan ReadTime();
4446
decimal ReadDecimal(int type, int scale);
4547
bool ReadBoolean();
48+
FbZonedDateTime ReadZonedDateTime(bool isExtended);
49+
FbZonedTime ReadZonedTime(bool isExtended);
50+
FbDecFloat ReadDec16();
51+
FbDecFloat ReadDec34();
52+
BigInteger ReadInt128();
4653
IscException ReadStatusVector();
4754
int ReadOperation();
4855
Task<int> ReadOperationAsync();

0 commit comments

Comments
 (0)