1

When writing the customized the converter in pyodbc, how to call the default converter? I am interested in customize the SQL_DECIMAL data type conversion and have the trailing zero stripped. I am thinking the 2 following options:

1) calling the default converter for SQL_DECIMAL and then convert it str, and strip trailng zeros.

2) or unpack the SQL_DECIMAL directly, which I don't know how to do yet.

def decimal_converter1(val):
    # calling pyodbc's own decimal converter
    s = str(val)
    return s.rstrip('0')

def decimal_converter2(val):
    # struct.unpack(?, val)
    return

cn.add_output_converter(pyodbc.SQL_DECIMAL, decimal_converter1)

pyodbc: 4.0.23, python 3.6.6, sql server 2014

0xInfection
  • 2,676
  • 1
  • 19
  • 34
fivelements
  • 1,487
  • 2
  • 19
  • 32

0 Answers0