[DB-SIG] Controlling return types for DB APIs

Federico Di Gregorio fog at initd.org
Tue Apr 17 09:44:19 CEST 2007

Il giorno mar, 17/04/2007 alle 00.05 -0400, Jim Patterson ha scritto:
> Over on the cx_Oracle list we have been discussing adding support
> for returning native Unicode strings and decimal objects.  We have
> so far been talking about using a settable attribute on the connection
> and the cursor with the cursor inheriting the value from the
> connection
> by default.  The is very similar to the existing technique used
> by cx_Oracle for the "numbersAsString" and the technique used
> by mxODBC for the "stringFormat" and "datetimeFormat". 
> Anyone have any thoughts/feelings/opinions about moving towards
> standardizing how we do this kind of thing across the different
> database modules? 

psycopg's type system is one of its best features (and one loved by
users I was told). At any time you can create a new "type" as

nt = psycopg2.new_type((oid1, oid2, ...), "name", typecast_func)

and then register it using "psycopg2.register_type(nt)". This has 2

     1. data described by listed oids (this is PostgreSQL-specific, I
        know) is converted using the function "typecast_func"; and
     2. you can use "nt" as a type object in comparaisons, just like
        other type object in the dbapi (STRING, NUMERIC, etc...)


Federico Di Gregorio                         http://people.initd.org/fog
Debian GNU/Linux Developer                                fog at debian.org
INIT.D Developer                                           fog at initd.org
  Se consideri l'uso del software libero una concessione tu stesso,
   come potrai proporla agli altri?                         -- Nick Name
-------------- 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/72dee7c3/attachment.pgp 

More information about the DB-SIG mailing list