Ignore:
Timestamp:
Jan 30, 2016, 2:55:18 PM (3 years ago)
Author:
cito
Message:

Port type cache and typecasting from pgdb to pg

So far, the typecasting in the classic module was been only done by
the C extension module and was not extensible through typecasting
functions in Python. This has now been made extensible by adding
a cast hook to the C extension module which has been hooked up to
a new type cache object that holds information on the types and the
associated typecast functions. All of this works very similar to the
pgdb module now, except that the basic types are still handled by
the C extension module and the Python typecast functions are only
called via the hook for types which are not supported internally.

Also added tests and a chapter on the type cache in the documentation,
and cleaned up the error messages in the C extension module.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/test_dbapi20.py

    r797 r798  
    309309            self.assertNotIn('pg_type', type_cache)
    310310            type_info = type_cache['pg_type']
    311             self.assertIn('numeric', type_cache)
     311            self.assertIn('pg_type', type_cache)
    312312            self.assertEqual(type_info.type, 'c')  # composite
    313313            self.assertEqual(type_info.category, 'C')  # composite
     
    357357            self.assertEqual(i4, 'int(4)')
    358358            self.assertEqual(i8, 8)
    359             self.assertEqual(type_cache.typecast('int4', 42), 'int(42)')
     359            self.assertEqual(type_cache.typecast(42, 'int4'), 'int(42)')
    360360            type_cache.set_typecast(['int2', 'int8'], cast_int)
    361361            cur.execute(query)
Note: See TracChangeset for help on using the changeset viewer.