[DB-SIG] Controlling return types for DB APIs

Federico Di Gregorio fog at initd.org
Tue Apr 17 10:29:34 CEST 2007

Il giorno mar, 17/04/2007 alle 10.16 +0200, M.-A. Lemburg ha scritto:
> While this can be solved using a registry of types conversions,
> I see problems in standardizing the way to define the type
> mappings since different database backends tend to have
> or need different types. 

I can see an API that leverages on the introspection abilities of the
drivers, to abstract to the different type representations of the
various backends. Let's suppose that a driver "knows" the type of a DB
column, then we can ask it for an abstract "dbtype":

dbtype = connection_object.getdbtype("SELECT 1 AS foo")

where the query _must_ return a scalar from which the driver infers the
type. Then the type can be used as a key in the registry. Obviously the
conversion function will be backend-specific but I suppose the signature
couldbe the same for all functions. Given the fact that the conversion
happens inside a cursor and than the connection is available from the
cursor object itself, something like:

py_data = conversion_function(backend_data, cursor_object)

Then we can at least make a standard for the registry methods.


Federico Di Gregorio                         http://people.initd.org/fog
Debian GNU/Linux Developer                                fog at debian.org
INIT.D Developer                                           fog at initd.org
              All programmers are optimists. -- Frederick P. Brooks, Jr.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Questa =?ISO-8859-1?Q?=E8?= una parte del messaggio
	firmata digitalmente
Url : http://mail.python.org/pipermail/db-sig/attachments/20070417/f1865f52/attachment.pgp 

More information about the DB-SIG mailing list