Search code examples
python-3.xcx-oracle

outputtypehandler ( TypeError: expecting variable with array size large enough for fetch)


Using outputtypehandler to fetch data from Oracle using Python's Cx_Oracle module but getting the following error.

TypeError: expecting variable with array size large enough for fetch

def OutputTypeHandler(cursor, name, defaultType, size, precision, scale):
    if defaultType in (cx_Oracle.DB_TYPE_TIMESTAMP, cx_Oracle.DB_TYPE_DATE):
        return cursor.var(datetime.date,cursor.arraysize)

Could anyone please help resolve the issue.


Solution

  • You are very close. You want this instead:

    def OutputTypeHandler(cursor, name, defaultType, size, precision, scale):
        if defaultType in (cx_Oracle.DB_TYPE_TIMESTAMP, cx_Oracle.DB_TYPE_DATE):
            return cursor.var(datetime.date, arraysize=cursor.arraysize)
    

    The second parameter to cursor.var() is the size of the value (used for strings, not for dates). You want the third parameter which is the arraysize!