From: Daniele Varrazzo Date: Sun, 9 May 2021 23:22:12 +0000 (+0200) Subject: Fix dumping Decimal of the form 0E+n X-Git-Tag: 3.0.dev0~48^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=43a5adff7d811d8488550669205fb9689442b618;p=thirdparty%2Fpsycopg.git Fix dumping Decimal of the form 0E+n --- diff --git a/psycopg3/psycopg3/types/numeric.py b/psycopg3/psycopg3/types/numeric.py index ebfeb9896..0108e95aa 100644 --- a/psycopg3/psycopg3/types/numeric.py +++ b/psycopg3/psycopg3/types/numeric.py @@ -401,9 +401,6 @@ class DecimalBinaryDumper(Dumper): while nzdigits > 0 and digits[nzdigits - 1] == 0: nzdigits -= 1 - if not nzdigits: - return _pack_numeric_head(0, 0, NUMERIC_POS, -exp) - if exp <= 0: dscale = -exp else: @@ -411,6 +408,9 @@ class DecimalBinaryDumper(Dumper): # align the py digits to the pg digits if there's some py exponent ndigits += exp % DEC_DIGITS + if not nzdigits: + return _pack_numeric_head(0, 0, NUMERIC_POS, dscale) + # Equivalent of 0-padding left to align the py digits to the pg digits # but without changing the digits tuple. mod = (ndigits - dscale) % DEC_DIGITS diff --git a/psycopg3_c/psycopg3_c/types/numeric.pyx b/psycopg3_c/psycopg3_c/types/numeric.pyx index 72e6586ef..a2646047f 100644 --- a/psycopg3_c/psycopg3_c/types/numeric.pyx +++ b/psycopg3_c/psycopg3_c/types/numeric.pyx @@ -595,15 +595,6 @@ cdef class DecimalBinaryDumper(CDumper): while nzdigits > 0 and digits[nzdigits - 1] == 0: nzdigits -= 1 - if nzdigits == 0: - length = 4 * sizeof(uint16_t) - buf = CDumper.ensure_size(rv, offset, length) - buf[0] = 0 # ndigits - buf[1] = 0 # weight - buf[2] = endian.htobe16(NUMERIC_POS) # sign - buf[3] = endian.htobe16(-exp) # dscale - return length - cdef uint16_t dscale if exp <= 0: dscale = -exp @@ -612,6 +603,15 @@ cdef class DecimalBinaryDumper(CDumper): # align the py digits to the pg digits if there's some py exponent ndigits += exp % DEC_DIGITS + if nzdigits == 0: + length = 4 * sizeof(uint16_t) + buf = CDumper.ensure_size(rv, offset, length) + buf[0] = 0 # ndigits + buf[1] = 0 # weight + buf[2] = endian.htobe16(NUMERIC_POS) # sign + buf[3] = endian.htobe16(dscale) + return length + # Equivalent of 0-padding left to align the py digits to the pg digits # but without changing the digits tuple. cdef int wi = 0