|
From: <sub...@co...> - 2007-01-16 14:05:27
|
Author: phd Date: 2007-01-16 07:05:23 -0700 (Tue, 16 Jan 2007) New Revision: 2207 Modified: SQLObject/docs/News.txt SQLObject/docs/SQLObject.txt Log: MySQLConnection got new keyword "conv" - a list of custom converters. Modified: SQLObject/docs/News.txt =================================================================== --- SQLObject/docs/News.txt 2007-01-16 14:00:51 UTC (rev 2206) +++ SQLObject/docs/News.txt 2007-01-16 14:05:23 UTC (rev 2207) @@ -34,6 +34,8 @@ .. _Versioning: Versioning.html +* MySQLConnection got new keyword "conv" - a list of custom converters. + Small Features -------------- Modified: SQLObject/docs/SQLObject.txt =================================================================== --- SQLObject/docs/SQLObject.txt 2007-01-16 14:00:51 UTC (rev 2206) +++ SQLObject/docs/SQLObject.txt 2007-01-16 14:05:23 UTC (rev 2207) @@ -1534,6 +1534,29 @@ does not have support for explicitly defining the backend when using ``createTable``. +Keyword argument "conv" allows to pass a list of custom converters. +Example:: + + import time + import sqlobject + import MySQLdb.converters + + def _mysql_timestamp_converter(raw): + """Convert a MySQL TIMESTAMP to a floating point number representing + the seconds since the Un*x Epoch. It uses custom code the input seems + to be the new (MySQL 4.1+) timestamp format, otherwise code from the + MySQLdb module is used.""" + if raw[4] == '-': + return time.mktime(time.strptime(raw, '%Y-%m-%d %H:%M:%S')) + else: + return MySQLdb.converters.mysql_timestamp_converter(raw) + + conversions = MySQLdb.converters.conversions.copy() + conversions[MySQLdb.constants.FIELD_TYPE.TIMESTAMP] = _mysql_timestamp_converter + + MySQLConnection = sqlobject.mysql.builder() + connection = MySQLConnection(user='foo', db='somedb', conv=conversions) + Postgres -------- |