[DB-SIG] checking column types from cursor object in a database-independent way?
dlenski at gmail.com
Tue Apr 23 17:00:18 CEST 2013
On Tue, Apr 23, 2013 at 12:29 AM, M.-A. Lemburg <mal at egenix.com> wrote:
> I don't think we should clutter up the connection objects with
> module scope attributes that hardly ever get used.
> The exceptions are used a lot, so it makes sense to have them
> easily available via the connection object - even though I'm not
> sure whether that particular DB-API extension was such a
> good idea w/r to API design (it's one of those practicality beats
> purity things).
Again, I understand the desire not to cruft up the cursor or
connection namespaces, but I am sort of surprised that you consider
the type objects to be little-used. It seems to me that they are a
necessity for any abstract DB-independent layer.
> Adding access to the database module via the connection object
> would allow to resolve all this. The problem
> with doing so is that you typically don't want the module
> object to be referenced directly by hundreds of objects in your
> application and you can also run into problems when reloading
> modules or (depending on how this is implemented) circular
> A method doing the lookup via the sys.modules dictionary
> could resolve those issues:
> database = connection.database()
> cursor = connection.cursor()
> except database.DataError:
> Thoughts ?
This seems like a reasonable solution to me, that would solve both
this problem as well as similar ones.
Alternatively, a cursor.coltypes attribute (in term containing
.STRING, .DATETIME, etc.) would solve the present problem.
More information about the DB-SIG