Skip to content

Commit

Permalink
Fix: DECFLOAT ARRAYs do not work
Browse files Browse the repository at this point in the history
  • Loading branch information
pcisar committed Jul 26, 2024
1 parent f9a0276 commit 3bab8e3
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [1.10.5] - 2024-07-26

### Fixed

- Unregistered bug: DECFLOAT ARRAYs do not work.

## [1.10.4] - 2024-05-07

### Added
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Changelog
#########

Version 1.10.5
==============

- Fix: DECFLOAT ARRAYs do not work.

Version 1.10.4
==============

Expand Down
2 changes: 1 addition & 1 deletion src/firebird/driver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@
Server, Statement)

#: Current driver version, SEMVER string.
__VERSION__ = '1.10.4'
__VERSION__ = '1.10.5'
13 changes: 7 additions & 6 deletions src/firebird/driver/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3143,6 +3143,10 @@ def _copy_list_to_db_array(self, esize: int, dtype: int, subtype: int,
valuebuf = create_string_buffer(bytes([0]), esize)
elif dtype == a.blr_bool:
valuebuf = create_string_buffer(bytes([0]), esize)
elif dtype in (a.blr_int128, a.blr_dec64, a.blr_dec128):
valuebuf = create_string_buffer(bytes([0]), esize)
elif dtype in (a.blr_sql_time_tz, a.blr_timestamp_tz):
valuebuf = create_string_buffer(bytes([0]), esize)
else: # pragma: no cover
raise InterfaceError(f"Unsupported Firebird ARRAY subtype: {dtype}")
self._fill_db_array_buffer(esize, dtype,
Expand Down Expand Up @@ -3216,14 +3220,11 @@ def _fill_db_array_buffer(self, esize: int, dtype: int, subtype: int,
valuebuf.value = _util.encode_timestamp_tz(value[i])
memmove(byref(buf, bufpos), valuebuf, esize)
elif dtype == a.blr_dec64:
valuebuf.value = _util.get_decfloat16().from_str(str(value[i]))
memmove(byref(buf, bufpos), valuebuf, esize)
memmove(byref(buf, bufpos), byref(_util.get_decfloat16().from_str(str(value[i]))), esize)
elif dtype == a.blr_dec128:
valuebuf.value = _util.get_decfloat34().from_str(str(value[i]))
memmove(byref(buf, bufpos), valuebuf, esize)
memmove(byref(buf, bufpos), _util.get_decfloat34().from_str(str(value[i])), esize)
elif dtype == a.blr_int128:
valuebuf.value = _util.get_int128().from_str(str(value), scale)
memmove(byref(buf, bufpos), valuebuf, esize)
memmove(byref(buf, bufpos), _util.get_int128().from_str(str(value[i]), scale), esize)
else: # pragma: no cover
raise InterfaceError(f"Unsupported Firebird ARRAY subtype: {dtype}")
bufpos += esize
Expand Down
Binary file modified tests/fbtest40.fdb
Binary file not shown.
Binary file modified tests/fbtest50.fdb
Binary file not shown.
53 changes: 51 additions & 2 deletions tests/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,9 @@ def setUp(self):
c12 double precision[2],
c13 decimal(10,1)[2],
c14 decimal(10,5)[2],
c15 decimal(18,5)[2]
c15 decimal(18,5)[2],
c16 boolean[2],
c17 decfloat[2]
)
"""
#
Expand Down Expand Up @@ -2681,7 +2683,7 @@ def test_07_select_int128(self):
self.assertEqual(n128, d)
self.assertIsInstance(d128, decimal.Decimal)
self.assertEqual(d128, d)
def test_08_select_int128(self):
def test_08_insert_int128(self):
data = {5: (decimal.Decimal('1111111111222222222233333333.334444'),decimal.Decimal('1111111111222222222233333333.334444')),
6: (decimal.Decimal('111111111122222222223333333333.4444'),decimal.Decimal('111111111122222222223333333333.4444')),
7: (decimal.Decimal('111111111122222222223333333333.444455'),decimal.Decimal('111111111122222222223333333333.444455')),
Expand All @@ -2698,6 +2700,53 @@ def test_08_select_int128(self):
self.assertEqual(n128, d[1])
self.assertIsInstance(d128, decimal.Decimal)
self.assertEqual(d128, d[1])
def test_09_array_defloat(self):
d_df = [decimal.Decimal('1111111111222222222233333333334444'),
decimal.Decimal('1111111111222222222233333333334445')]
d_df16 = [decimal.Decimal('1111111111222222'),
decimal.Decimal('1111111111222223')]
d_df34 = [decimal.Decimal('1111111111222222222233333333334444'),
decimal.Decimal('1111111111222222222233333333334445')]
data = {9: (d_df, d_df16, d_df34),
}
with self.con.cursor() as cur:
for pk, d in data.items():
cur.execute("insert into FB4 (PK,ADF,ADF16,ADF34) values (?, ?, ?, ?)", (pk, d[0], d[1], d[2]))
self.con.commit()
cur.execute('select PK,ADF,ADF16,ADF34 from FB4 where PK = 9')
for pk, adf, adf16, adf34 in cur:
d = data[pk]
self.assertIsInstance(adf, list)
for v in adf:
self.assertIsInstance(v, decimal.Decimal)
self.assertEqual(adf, d_df)
self.assertIsInstance(adf16, list)
for v in adf16:
self.assertIsInstance(v, decimal.Decimal)
self.assertEqual(adf16, d_df16)
self.assertIsInstance(adf34, list)
for v in adf34:
self.assertIsInstance(v, decimal.Decimal)
self.assertEqual(adf34, d_df34)
def test_10_array_int128(self):
d_int128 = [decimal.Decimal('1111111111222222222233333333.334444'),
decimal.Decimal('1111111111222222222233333333.334444')]
data = {11: (d_int128)}
with self.con.cursor() as cur:
for pk, d in data.items():
cur.execute("insert into FB4 (PK,AN128,AD128) values (?, ?, ?)", (pk, d, d))
self.con.commit()
cur.execute('select PK,AN128,AD128 from FB4 where PK = 11 order by pk')
for pk, an128, ad128 in cur:
d = data[pk]
self.assertIsInstance(an128, list)
for v in an128:
self.assertIsInstance(v, decimal.Decimal)
self.assertEqual(an128, d)
self.assertIsInstance(ad128, list)
for v in ad128:
self.assertIsInstance(v, decimal.Decimal)
self.assertEqual(ad128, d)

class TestIssues(DriverTestBase):
def setUp(self):
Expand Down

0 comments on commit 3bab8e3

Please sign in to comment.