Re: checking column types from cursor object in a database-independent way?

Daniel Lenski <[email protected]>
Newsgroups gmane.comp.python.db
Message-ID <CAOw_LSHAusvPCaBh-NaWOqaD6HDBEEMf-zChPPkKGVNfNwmiKw@mail.gmail.com>
On Tue, Apr 23, 2013 at 12:29 AM, M.-A. Lemburg <[email protected]> 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
> references.
>
> A method doing the lookup via the sys.modules dictionary
> could resolve those issues:
>
> database = connection.database()
> try:
>     cursor = connection.cursor()
>     cursor.execute(...)
> 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.

Dan
_______________________________________________
DB-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/db-sig
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.