Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2b7040a

Browse files
committed
fix#53 Loss of scale when reading numeric with zero value
1 parentc829350 commit2b7040a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

‎src/firebird/driver/core.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3392,7 +3392,7 @@ def _extract_db_array_to_list(self, esize: int, dtype: int, subtype: int,
33923392
elifdtypein (a.blr_short,a.blr_long,a.blr_int64):
33933393
val= (0).from_bytes(buf[bufpos:bufpos+esize],'little',signed=True)
33943394
ifsubtypeorscale:
3395-
val=decimal.Decimal(val)/_ten_to[abs(scale)]
3395+
val=decimal.Decimal(val).scaleb(-abs(scale))
33963396
elifdtype==a.blr_bool:
33973397
val= (0).from_bytes(buf[bufpos:bufpos+esize],'little')==1
33983398
elifdtype==a.blr_float:
@@ -3799,7 +3799,7 @@ def _unpack_output(self) -> tuple:
37993799
value= (0).from_bytes(buffer[offset:offset+length],'little',signed=True)
38003800
# It's scalled integer?
38013801
ifdesc.subtypeordesc.scale:
3802-
value=decimal.Decimal(value)/_ten_to[abs(desc.scale)]
3802+
value=decimal.Decimal(value).scaleb(-abs(desc.scale))
38033803
elifdatatype==SQLDataType.DATE:
38043804
value=_util.decode_date(buffer[offset:offset+length])
38053805
elifdatatype==SQLDataType.TIME:

‎tests/test_issues.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,11 @@ def test_issue_02(db_connection):
3131
cur.execute('select C1,C2,C3 from T2 where C1 = 1')
3232
rows=cur.fetchall()
3333
assertrows== [(1,None,1)]
34+
35+
deftest_issue_53(db_connection):
36+
withdb_connection.cursor()ascur:
37+
cur.execute("select cast('0.00' as numeric(9,2)) from rdb$database")
38+
numeric_val=cur.fetchone()[0]
39+
numeric_val_exponent=numeric_val.as_tuple()[2]
40+
db_connection.commit()
41+
assertnumeric_val_exponent==-2

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp