Fix decimal type conversion for Jython

master
baztian 2020-06-03 22:17:55 +02:00
parent 78791871b0
commit 694197128a
2 changed files with 7 additions and 6 deletions

View File

@ -163,6 +163,7 @@ Changelog
- Return (big) decimal types as long value if scale is zero (thanks - Return (big) decimal types as long value if scale is zero (thanks
to @ministat) to @ministat)
- Fix `DECIMAL` and `NUMERIC` type conversion for Jython
- 1.2.1 - 2020-05-27 - 1.2.1 - 2020-05-27

View File

@ -663,19 +663,19 @@ def _java_to_py(java_method):
return getattr(java_val, java_method)() return getattr(java_val, java_method)()
return to_py return to_py
def _java_to_py_bigdecimal(java_method): def _java_to_py_bigdecimal():
def to_py(rs, col): def to_py(rs, col):
java_val = rs.getObject(col) java_val = rs.getObject(col)
if java_val is None: if java_val is None:
return return
if hasattr(java_val, 'scale'): if hasattr(java_val, 'scale'):
scale = getattr(java_val, 'scale')() scale = java_val.scale()
if scale == 0: if scale == 0:
return getattr(java_val, 'longValue')() return java_val.longValue()
else: else:
return getattr(java_val, java_method)() return java_val.doubleValue()
else: else:
return getattr(java_val, java_method)() return float(java_val)
return to_py return to_py
_to_double = _java_to_py('doubleValue') _to_double = _java_to_py('doubleValue')
@ -684,7 +684,7 @@ _to_int = _java_to_py('intValue')
_to_boolean = _java_to_py('booleanValue') _to_boolean = _java_to_py('booleanValue')
_to_decimal = _java_to_py_bigdecimal('doubleValue') _to_decimal = _java_to_py_bigdecimal()
def _init_types(types_map): def _init_types(types_map):
global _jdbc_name_to_const global _jdbc_name_to_const