Skip to content

Commit 3bab8e3

Browse files
committed
Fix: DECFLOAT ARRAYs do not work
1 parent f9a0276 commit 3bab8e3

File tree

7 files changed

+70
-9
lines changed

7 files changed

+70
-9
lines changed

Diff for: CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [1.10.5] - 2024-07-26
8+
9+
### Fixed
10+
11+
- Unregistered bug: DECFLOAT ARRAYs do not work.
12+
713
## [1.10.4] - 2024-05-07
814

915
### Added

Diff for: docs/changelog.txt

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
Changelog
33
#########
44

5+
Version 1.10.5
6+
==============
7+
8+
- Fix: DECFLOAT ARRAYs do not work.
9+
510
Version 1.10.4
611
==============
712

Diff for: src/firebird/driver/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@
6161
Server, Statement)
6262

6363
#: Current driver version, SEMVER string.
64-
__VERSION__ = '1.10.4'
64+
__VERSION__ = '1.10.5'

Diff for: src/firebird/driver/core.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -3143,6 +3143,10 @@ def _copy_list_to_db_array(self, esize: int, dtype: int, subtype: int,
31433143
valuebuf = create_string_buffer(bytes([0]), esize)
31443144
elif dtype == a.blr_bool:
31453145
valuebuf = create_string_buffer(bytes([0]), esize)
3146+
elif dtype in (a.blr_int128, a.blr_dec64, a.blr_dec128):
3147+
valuebuf = create_string_buffer(bytes([0]), esize)
3148+
elif dtype in (a.blr_sql_time_tz, a.blr_timestamp_tz):
3149+
valuebuf = create_string_buffer(bytes([0]), esize)
31463150
else: # pragma: no cover
31473151
raise InterfaceError(f"Unsupported Firebird ARRAY subtype: {dtype}")
31483152
self._fill_db_array_buffer(esize, dtype,
@@ -3216,14 +3220,11 @@ def _fill_db_array_buffer(self, esize: int, dtype: int, subtype: int,
32163220
valuebuf.value = _util.encode_timestamp_tz(value[i])
32173221
memmove(byref(buf, bufpos), valuebuf, esize)
32183222
elif dtype == a.blr_dec64:
3219-
valuebuf.value = _util.get_decfloat16().from_str(str(value[i]))
3220-
memmove(byref(buf, bufpos), valuebuf, esize)
3223+
memmove(byref(buf, bufpos), byref(_util.get_decfloat16().from_str(str(value[i]))), esize)
32213224
elif dtype == a.blr_dec128:
3222-
valuebuf.value = _util.get_decfloat34().from_str(str(value[i]))
3223-
memmove(byref(buf, bufpos), valuebuf, esize)
3225+
memmove(byref(buf, bufpos), _util.get_decfloat34().from_str(str(value[i])), esize)
32243226
elif dtype == a.blr_int128:
3225-
valuebuf.value = _util.get_int128().from_str(str(value), scale)
3226-
memmove(byref(buf, bufpos), valuebuf, esize)
3227+
memmove(byref(buf, bufpos), _util.get_int128().from_str(str(value[i]), scale), esize)
32273228
else: # pragma: no cover
32283229
raise InterfaceError(f"Unsupported Firebird ARRAY subtype: {dtype}")
32293230
bufpos += esize

Diff for: tests/fbtest40.fdb

0 Bytes
Binary file not shown.

Diff for: tests/fbtest50.fdb

0 Bytes
Binary file not shown.

Diff for: tests/test_driver.py

+51-2
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,9 @@ def setUp(self):
12051205
c12 double precision[2],
12061206
c13 decimal(10,1)[2],
12071207
c14 decimal(10,5)[2],
1208-
c15 decimal(18,5)[2]
1208+
c15 decimal(18,5)[2],
1209+
c16 boolean[2],
1210+
c17 decfloat[2]
12091211
)
12101212
"""
12111213
#
@@ -2681,7 +2683,7 @@ def test_07_select_int128(self):
26812683
self.assertEqual(n128, d)
26822684
self.assertIsInstance(d128, decimal.Decimal)
26832685
self.assertEqual(d128, d)
2684-
def test_08_select_int128(self):
2686+
def test_08_insert_int128(self):
26852687
data = {5: (decimal.Decimal('1111111111222222222233333333.334444'),decimal.Decimal('1111111111222222222233333333.334444')),
26862688
6: (decimal.Decimal('111111111122222222223333333333.4444'),decimal.Decimal('111111111122222222223333333333.4444')),
26872689
7: (decimal.Decimal('111111111122222222223333333333.444455'),decimal.Decimal('111111111122222222223333333333.444455')),
@@ -2698,6 +2700,53 @@ def test_08_select_int128(self):
26982700
self.assertEqual(n128, d[1])
26992701
self.assertIsInstance(d128, decimal.Decimal)
27002702
self.assertEqual(d128, d[1])
2703+
def test_09_array_defloat(self):
2704+
d_df = [decimal.Decimal('1111111111222222222233333333334444'),
2705+
decimal.Decimal('1111111111222222222233333333334445')]
2706+
d_df16 = [decimal.Decimal('1111111111222222'),
2707+
decimal.Decimal('1111111111222223')]
2708+
d_df34 = [decimal.Decimal('1111111111222222222233333333334444'),
2709+
decimal.Decimal('1111111111222222222233333333334445')]
2710+
data = {9: (d_df, d_df16, d_df34),
2711+
}
2712+
with self.con.cursor() as cur:
2713+
for pk, d in data.items():
2714+
cur.execute("insert into FB4 (PK,ADF,ADF16,ADF34) values (?, ?, ?, ?)", (pk, d[0], d[1], d[2]))
2715+
self.con.commit()
2716+
cur.execute('select PK,ADF,ADF16,ADF34 from FB4 where PK = 9')
2717+
for pk, adf, adf16, adf34 in cur:
2718+
d = data[pk]
2719+
self.assertIsInstance(adf, list)
2720+
for v in adf:
2721+
self.assertIsInstance(v, decimal.Decimal)
2722+
self.assertEqual(adf, d_df)
2723+
self.assertIsInstance(adf16, list)
2724+
for v in adf16:
2725+
self.assertIsInstance(v, decimal.Decimal)
2726+
self.assertEqual(adf16, d_df16)
2727+
self.assertIsInstance(adf34, list)
2728+
for v in adf34:
2729+
self.assertIsInstance(v, decimal.Decimal)
2730+
self.assertEqual(adf34, d_df34)
2731+
def test_10_array_int128(self):
2732+
d_int128 = [decimal.Decimal('1111111111222222222233333333.334444'),
2733+
decimal.Decimal('1111111111222222222233333333.334444')]
2734+
data = {11: (d_int128)}
2735+
with self.con.cursor() as cur:
2736+
for pk, d in data.items():
2737+
cur.execute("insert into FB4 (PK,AN128,AD128) values (?, ?, ?)", (pk, d, d))
2738+
self.con.commit()
2739+
cur.execute('select PK,AN128,AD128 from FB4 where PK = 11 order by pk')
2740+
for pk, an128, ad128 in cur:
2741+
d = data[pk]
2742+
self.assertIsInstance(an128, list)
2743+
for v in an128:
2744+
self.assertIsInstance(v, decimal.Decimal)
2745+
self.assertEqual(an128, d)
2746+
self.assertIsInstance(ad128, list)
2747+
for v in ad128:
2748+
self.assertIsInstance(v, decimal.Decimal)
2749+
self.assertEqual(ad128, d)
27012750

27022751
class TestIssues(DriverTestBase):
27032752
def setUp(self):

0 commit comments

Comments
 (0)