[DB-SIG] DCOracle number handling still broken?

alexander smishlajev alex@ank-sia.com
Sat, 20 May 2000 07:51:21 +0200


alexander smishlajev wrote:
> 
> the following patch may be applied to obtain best-fit result for
> numbers: long if possible (i.e. no decimal digits, and no more
> than 18 digits) or float otherwise:

i am sorry, that code was far from functional.  now the following
conversion procedure is used here:

=== cut ===
def varnum(buf):
    """convert OCI_EXTERNAL_VARNUM to number (long or float)"""
    a =array('b', buf).tolist()
    _mlen =a[0] -1 # mantissa length
    _exp =a[1]     # exponent & sign
    if _exp <0:
        s ='+0'; _neg =0; _exp =_exp +64
    else:
        s ='-0'; _neg =1; _exp =63 -_exp
        if (_mlen <19) or (a[20] ==102): _mlen =_mlen -1
    if _exp <0: s =s +'.' +'00' *(-_exp)
    for _byte in a[2:_mlen+2]:
        if _exp ==0: s =s +'.'
        _exp =_exp -1
        if _neg: s =s +'%02i' %(101 -_byte)
        else: s =s +'%02i' %(_byte -1)
    if _exp >0: s =s +'00' *_exp
    if ('.' not in s) and (len(s) <12): return int(s)
    elif ('.' not in s) and (len(s) <20): return long(s)
    else: return float(s)
=== cut ===

best wishes,
alex.