diff --git a/ChangeLog b/ChangeLog index cac156d8..ad4b3c08 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-05-04 Daniele Varrazzo + + * Added typecasters for arrays of specific MX/Py time-related types. + 2010-05-03 Daniele Varrazzo * psycopg/adapter_binary.c: Adapt buffer objects using an explicit cast on diff --git a/doc/src/extensions.rst b/doc/src/extensions.rst index 839ed67f..268befa5 100644 --- a/doc/src/extensions.rst +++ b/doc/src/extensions.rst @@ -537,6 +537,10 @@ from the database. See :ref:`unicode-handling` for details. PYDATETIME PYINTERVAL PYTIME + PYDATEARRAY + PYDATETIMEARRAY + PYINTERVALARRAY + PYTIMEARRAY Typecasters to convert time-related data types to Python `!datetime` objects. @@ -545,6 +549,10 @@ from the database. See :ref:`unicode-handling` for details. MXDATETIME MXINTERVAL MXTIME + MXDATEARRAY + MXDATETIMEARRAY + MXINTERVALARRAY + MXTIMEARRAY Typecasters to convert time-related data types to `mx.DateTime`_ objects. Only available if Psycopg was compiled with `!mx` support. diff --git a/lib/extensions.py b/lib/extensions.py index 7290d5b4..eea90d48 100644 --- a/lib/extensions.py +++ b/lib/extensions.py @@ -42,6 +42,7 @@ from _psycopg import UNICODEARRAY from _psycopg import Binary, Boolean, Float, QuotedString, AsIs try: from _psycopg import MXDATE, MXDATETIME, MXINTERVAL, MXTIME + from _psycopg import MXDATEARRAY, MXDATETIMEARRAY, MXINTERVALARRAY, MXTIMEARRAY from _psycopg import DateFromMx, TimeFromMx, TimestampFromMx from _psycopg import IntervalFromMx except: @@ -49,6 +50,7 @@ except: try: from _psycopg import PYDATE, PYDATETIME, PYINTERVAL, PYTIME + from _psycopg import PYDATEARRAY, PYDATETIMEARRAY, PYINTERVALARRAY, PYTIMEARRAY from _psycopg import DateFromPy, TimeFromPy, TimestampFromPy from _psycopg import IntervalFromPy except: diff --git a/psycopg/typecast.c b/psycopg/typecast.c index 326d3ea5..7b303e2a 100644 --- a/psycopg/typecast.c +++ b/psycopg/typecast.c @@ -182,6 +182,10 @@ typecast_parse_time(const char* s, const char** t, Py_ssize_t* len, #include "psycopg/typecast_array.c" #include "psycopg/typecast_builtins.c" +#define typecast_PYDATETIMEARRAY_cast typecast_GENERIC_ARRAY_cast +#define typecast_PYDATEARRAY_cast typecast_GENERIC_ARRAY_cast +#define typecast_PYTIMEARRAY_cast typecast_GENERIC_ARRAY_cast +#define typecast_PYINTERVALARRAY_cast typecast_GENERIC_ARRAY_cast /* a list of initializers, used to make the typecasters accessible anyway */ static typecastObject_initlist typecast_pydatetime[] = { @@ -189,16 +193,29 @@ static typecastObject_initlist typecast_pydatetime[] = { {"PYTIME", typecast_TIME_types, typecast_PYTIME_cast}, {"PYDATE", typecast_DATE_types, typecast_PYDATE_cast}, {"PYINTERVAL", typecast_INTERVAL_types, typecast_PYINTERVAL_cast}, + {"PYDATETIMEARRAY", typecast_DATETIMEARRAY_types, typecast_PYDATETIMEARRAY_cast, "PYDATETIME"}, + {"PYTIMEARRAY", typecast_TIMEARRAY_types, typecast_PYTIMEARRAY_cast, "PYTIME"}, + {"PYDATEARRAY", typecast_DATEARRAY_types, typecast_PYDATEARRAY_cast, "PYDATE"}, + {"PYINTERVALARRAY", typecast_INTERVALARRAY_types, typecast_PYINTERVALARRAY_cast, "PYINTERVAL"}, {NULL, NULL, NULL} }; -/* a list of initializers, used to make the typecasters accessible anyway */ #ifdef HAVE_MXDATETIME +#define typecast_MXDATETIMEARRAY_cast typecast_GENERIC_ARRAY_cast +#define typecast_MXDATEARRAY_cast typecast_GENERIC_ARRAY_cast +#define typecast_MXTIMEARRAY_cast typecast_GENERIC_ARRAY_cast +#define typecast_MXINTERVALARRAY_cast typecast_GENERIC_ARRAY_cast + +/* a list of initializers, used to make the typecasters accessible anyway */ static typecastObject_initlist typecast_mxdatetime[] = { {"MXDATETIME", typecast_DATETIME_types, typecast_MXDATE_cast}, {"MXTIME", typecast_TIME_types, typecast_MXTIME_cast}, {"MXDATE", typecast_DATE_types, typecast_MXDATE_cast}, {"MXINTERVAL", typecast_INTERVAL_types, typecast_MXINTERVAL_cast}, + {"MXDATETIMEARRAY", typecast_DATETIMEARRAY_types, typecast_MXDATETIMEARRAY_cast, "MXDATETIME"}, + {"MXTIMEARRAY", typecast_TIMEARRAY_types, typecast_MXTIMEARRAY_cast, "MXTIME"}, + {"MXDATEARRAY", typecast_DATEARRAY_types, typecast_MXDATEARRAY_cast, "MXDATE"}, + {"MXINTERVALARRAY", typecast_INTERVALARRAY_types, typecast_MXINTERVALARRAY_cast, "MXINTERVAL"}, {NULL, NULL, NULL} }; #endif