From: Gerhard H?r. <gha...@us...> - 2002-10-02 05:16:47
|
Update of /cvsroot/pypgsql/pypgsql/pyPgSQL In directory usw-pr-cvs1:/tmp/cvs-serv390/pyPgSQL Modified Files: PgSQL.py Log Message: 02OCT2002 gh Add support for the INTERVAL type. Index: PgSQL.py =================================================================== RCS file: /cvsroot/pypgsql/pypgsql/pyPgSQL/PgSQL.py,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** PgSQL.py 2 Oct 2002 04:52:56 -0000 1.16 --- PgSQL.py 2 Oct 2002 05:16:44 -0000 1.17 *************** *** 37,40 **** --- 37,41 ---- # - Take into account that libpq.PgInt8Type might not be | # available. | + # - Add support for the INTERVAL type. | # 08SEP2002 gh Fixed various problems with the PgResultSet: | # - Column (attribute and dictionary) access is now case- | *************** *** 526,529 **** --- 527,543 ---- self.__conn = None + def interval2datetimedelta(self, s): + """Parses both 7.0.x and 7.1.x styles of PostgreSQL INTERVALs""" + if s.startswith("-"): + factor = -1 + else: + factor = 1 + s = s.replace('days ', '').replace("-", "") + l = s.split() + if len(l) != 2: + l = ['0'] + l + return factor * (DateTime.DateTimeDelta(int(l[0])) \ + + DateTime.DateTimeDeltaFrom(l[1])) + def parseArray(self, s): """Parse a PostgreSQL array strings representation. *************** *** 727,731 **** return value else: ! return DateTime.ISO.ParseAny(value) elif _ftv == BINARY: if isinstance(value, PgBytea) or type(value) is PgLargeObjectType: --- 741,748 ---- return value else: ! if _ftv == PG_INTERVAL: ! return self.interval2datetimedelta(value) ! else: ! return DateTime.ISO.ParseAny(value) elif _ftv == BINARY: if isinstance(value, PgBytea) or type(value) is PgLargeObjectType: |