Skip to content

Commit

Permalink
Fix for TIMEZONE and INT128 ARRAYs
Browse files Browse the repository at this point in the history
  • Loading branch information
pcisar committed Aug 15, 2024
1 parent b46728c commit f32fe0a
Show file tree
Hide file tree
Showing 10 changed files with 1,072 additions and 7 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ 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.6] - 2024-08-15

### Fixed

- Unregistered bug: Big NUMERIC/DECIMAL (i.e. INT128) ARRAYs do not work.
- Unregistered bug: ARRAYs of TIME WITH TIMEZONE do not work.

## [1.10.5] - 2024-07-26

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

Version 1.10.6
==============

- Fix: Big NUMERIC/DECIMAL (i.e. INT128) ARRAYs do not work.
- Fix: ARRAYs of TIME WITH TIMEZONE do not work.

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

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.5'
__VERSION__ = '1.10.6'
10 changes: 5 additions & 5 deletions src/firebird/driver/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
_util = None
_thns = threading.local()

_tenTo = [10 ** x for x in range(20)]
_tenTo = [10 ** x for x in range(30)]
_i2name = {DbInfoCode.READ_SEQ_COUNT: 'sequential', DbInfoCode.READ_IDX_COUNT: 'indexed',
DbInfoCode.INSERT_COUNT: 'inserts', DbInfoCode.UPDATE_COUNT: 'updates',
DbInfoCode.DELETE_COUNT: 'deletes', DbInfoCode.BACKOUT_COUNT: 'backouts',
Expand Down Expand Up @@ -3078,7 +3078,7 @@ def _extract_db_array_to_list(self, esize: int, dtype: int, subtype: int,
elif dtype in (a.blr_short, a.blr_long, a.blr_int64):
val = (0).from_bytes(buf[bufpos:bufpos + esize], 'little', signed=True)
if subtype or scale:
val = decimal.Decimal(val) / _tenTo[abs(256-scale)]
val = decimal.Decimal(val) / _tenTo[abs(scale)]
elif dtype == a.blr_bool:
val = (0).from_bytes(buf[bufpos:bufpos + esize], 'little') == 1
elif dtype == a.blr_float:
Expand Down Expand Up @@ -3173,9 +3173,9 @@ def _fill_db_array_buffer(self, esize: int, dtype: int, subtype: int,
if subtype or scale:
val = value[i]
if isinstance(val, decimal.Decimal):
val = int((val * _tenTo[256-abs(scale)]).to_integral())
val = int((val * _tenTo[abs(scale)]).to_integral())
elif isinstance(val, (int, float)):
val = int(val * _tenTo[256-abs(scale)])
val = int(val * _tenTo[abs(scale)])
else:
raise TypeError(f'Objects of type {type(val)} are not '
f' acceptable input for'
Expand Down Expand Up @@ -3214,7 +3214,7 @@ def _fill_db_array_buffer(self, esize: int, dtype: int, subtype: int,
valuebuf.value = _util.encode_time(value[i]).to_bytes(4, 'little')
memmove(byref(buf, bufpos), valuebuf, esize)
elif dtype == a.blr_sql_time_tz:
valuebuf.value = _util.encode_time_tz(value[i]).to_bytes(esize, 'little')
valuebuf.value = _util.encode_time_tz(value[i])
memmove(byref(buf, bufpos), valuebuf, esize)
elif dtype == a.blr_timestamp_tz:
valuebuf.value = _util.encode_timestamp_tz(value[i])
Expand Down
2 changes: 1 addition & 1 deletion src/firebird/driver/fbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class ISC_ARRAY_DESC(Structure):
"ISC_ARRAY_DESC"
_fields_ = [
('array_desc_dtype', c_ubyte),
('array_desc_scale', c_ubyte), # was ISC_SCHAR),
('array_desc_scale', c_byte), # was ISC_SCHAR),
('array_desc_length', c_ushort),
('array_desc_field_name', c_char * 32),
('array_desc_relation_name', c_char * 32),
Expand Down
3 changes: 3 additions & 0 deletions src/firebird/driver/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1417,6 +1417,9 @@ def get_timezone(timezone: str=None) -> datetime.tzinfo:
for timezone tzinfo objects, but adds metadata neccessary to store timezone regions into
database instead zoned time, and to handle offset-based timezones in format required by
Firebird.
Arguments:
timezone: Timezone region specification or UTC offset.
"""
if timezone[0] in ('+', '-'):
timezone = 'UTC' + timezone
Expand Down
Binary file modified tests/fbtest40.fdb
Binary file not shown.
Loading

0 comments on commit f32fe0a

Please sign in to comment.