Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/firebird/driver/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3392,7 +3392,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) / _ten_to[abs(scale)]
val = decimal.Decimal(val).scaleb(-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 @@ -3799,7 +3799,7 @@ def _unpack_output(self) -> tuple:
value = (0).from_bytes(buffer[offset:offset + length], 'little', signed=True)
# It's scalled integer?
if desc.subtype or desc.scale:
value = decimal.Decimal(value) / _ten_to[abs(desc.scale)]
value = decimal.Decimal(value).scaleb(-abs(desc.scale))
elif datatype == SQLDataType.DATE:
value = _util.decode_date(buffer[offset:offset+length])
elif datatype == SQLDataType.TIME:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,11 @@ def test_issue_02(db_connection):
cur.execute('select C1,C2,C3 from T2 where C1 = 1')
rows = cur.fetchall()
assert rows == [(1, None, 1)]

def test_issue_53(db_connection):
with db_connection.cursor() as cur:
cur.execute("select cast('0.00' as numeric(9,2)) from rdb$database")
numeric_val = cur.fetchone()[0]
numeric_val_exponent = numeric_val.as_tuple()[2]
db_connection.commit()
assert numeric_val_exponent == -2