diff options
author | Federico Di Gregorio <fog@initd.org> | 2005-03-12 06:39:47 +0000 |
---|---|---|
committer | Federico Di Gregorio <fog@initd.org> | 2005-03-12 06:39:47 +0000 |
commit | 9316c6af537b17d3ecfc70b81aa9183a7023a99b (patch) | |
tree | 197c635da0a0ed590f891707572b083e71af5e6c /psycopg/typecast_datetime.c | |
parent | c639b92bd9c277c5504fee6cc38bd8d94414e9b1 (diff) | |
download | psycopg2-9316c6af537b17d3ecfc70b81aa9183a7023a99b.tar.gz |
Optimizations to type casting (in preparation to array support.)
Diffstat (limited to 'psycopg/typecast_datetime.c')
-rw-r--r-- | psycopg/typecast_datetime.c | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/psycopg/typecast_datetime.c b/psycopg/typecast_datetime.c index 0f29bfd..b02da58 100644 --- a/psycopg/typecast_datetime.c +++ b/psycopg/typecast_datetime.c @@ -34,15 +34,12 @@ extern PyObject *pyDeltaTypeP; /** DATE - cast a date into a date python object **/ static PyObject * -typecast_PYDATE_cast(PyObject *s, PyObject *curs) +typecast_PYDATE_cast(unsigned char *str, int len, PyObject *curs) { PyObject* obj = NULL; int n, y=0, m=0, d=0; - char *str; - if (s == Py_None) {Py_INCREF(s); return s;} - - str = PyString_AsString(s); + if (str == NULL) {Py_INCREF(Py_None); return Py_None;} /* check for infinity */ if (!strcmp(str, "infinity") || !strcmp(str, "-infinity")) { @@ -70,18 +67,16 @@ typecast_PYDATE_cast(PyObject *s, PyObject *curs) /** DATETIME - cast a timestamp into a datetime python object **/ static PyObject * -typecast_PYDATETIME_cast(PyObject *s, PyObject *curs) +typecast_PYDATETIME_cast(unsigned char *str, int len, PyObject *curs) { PyObject* obj = NULL; int n, y=0, m=0, d=0; int hh=0, mm=0; int tzh=0, tzm=0; double ss=0.0; - char tzs=0, *str; + char tzs=0; - if (s == Py_None) {Py_INCREF(s); return s;} - - str = PyString_AsString(s); + if (str == NULL) {Py_INCREF(Py_None); return Py_None;} /* check for infinity */ if (!strcmp(str, "infinity") || !strcmp(str, "-infinity")) { @@ -136,16 +131,13 @@ typecast_PYDATETIME_cast(PyObject *s, PyObject *curs) /** TIME - parse time into a time object **/ static PyObject * -typecast_PYTIME_cast(PyObject *s, PyObject *curs) +typecast_PYTIME_cast(unsigned char *str, int len, PyObject *curs) { PyObject* obj = NULL; int n, hh=0, mm=0; - double ss=0.0; - char *str; + double ss=0.0; - if (s == Py_None) {Py_INCREF(s); return s;} - - str = PyString_AsString(s); + if (str == NULL) {Py_INCREF(Py_None); return Py_None;} n = sscanf(str, "%d:%d:%lf", &hh, &mm, &ss); @@ -168,19 +160,15 @@ typecast_PYTIME_cast(PyObject *s, PyObject *curs) /** INTERVAL - parse an interval into a timedelta object **/ static PyObject * -typecast_PYINTERVAL_cast(PyObject *s, PyObject *curs) +typecast_PYINTERVAL_cast(unsigned char *str, int len, PyObject *curs) { long years = 0, months = 0, days = 0, denominator = 1; double hours = 0.0, minutes = 0.0, seconds = 0.0, hundredths = 0.0; double v = 0.0, sign = 1.0; int part = 0, sec; - double micro; - char *str; - if (s == Py_None) {Py_INCREF(s); return s;} - - str = PyString_AsString(s); + if (str == NULL) {Py_INCREF(Py_None); return Py_None;} Dprintf("typecast_PYINTERVAL_cast: s = %s", str); |