Package: python-pygresql Version: 1:3.6.1-1 Severity: normal Tags: patch
When passed an mx.DateTime instance on a locale where the decimal separator is a comma (',') an invalid SQL string will be generated. Processing mx.DateTimeDelta (e.g. for time values created by pgdb.Time constructor) is not supported at all. Date- and Time-values are returned as 'strings', instead of a proper mx.DateTime* instance (as stated by the constructors Date, Time and Timestamp). The added patch should solve these problems. --- pgdb-org.py 2005-06-29 16:06:08.000000000 +0200 +++ pgdb.py 2005-07-15 15:49:08.353029928 +0200 @@ -135,8 +135,16 @@ value = string.replace(value, ",", "") value = float(value) elif typ == DATETIME: - # format may differ ... we'll give string - pass + try: + try: + value = DateTime.ISO.ParseAny (value) + + except ValueError: + value = self.interval2DateTimeDelta (value) + + except: + pass + elif typ == ROWID: value = long(value) return value @@ -160,6 +168,34 @@ self.__type_cache[oid] = res return res + def interval2DateTimeDelta(self, s): + """Parses PostgreSQL INTERVALs. + The expected format is [[[-]YY years] [-]DD days] [-]HH:MM:SS.ss""" + parser = DateTime.Parser.DateTimeDeltaFromString + + ydh = s.split() + + result = DateTime.DateTimeDelta (0) + + # Convert any years using 365.2425 days per year, which is + # PostgreSQL's assumption about the number of days in a year. + if len(ydh) > 1: + if ydh[1].lower().startswith('year'): + result += parser('%s days' % ((int(ydh[0]) * 365.2425),)) + ydh = ydh[2:] + + # Converts any days and adds it to the years (as an interval) + if len(ydh) > 1: + if ydh[1].lower().startswith('day'): + result += parser('%s days' % (ydh[0],)) + ydh = ydh[2:] + + # Adds in the hours, minutes, seconds (as an interval) + if len(ydh) > 0: + result += parser(ydh[0]) + + return result + ### cursor object class pgdbCursor: @@ -271,7 +307,15 @@ except (NameError, AttributeError): def _quote(x): if isinstance(x, DateTime.DateTimeType): - x = str(x) + x = "%04d-%02d-%02d %02d:%02d:%09.6f" % (x.year, x.month, + x.day, x.hour, x.minute, x.second) + elif isinstance (x, DateTime.DateTimeDeltaType): + x = ("%s %02d:%02d:%09.6f%s" % ( \ + x.day and '%d days' % abs (x.day) or '', + abs (x.hour), abs (x.minute), abs (x.second), + x.day < 0 and ' ago' or '')).strip () + + if isinstance(x, types.StringType): x = "'" + string.replace( string.replace(str(x), '\\', '\\\\'), "'", "''") + "'" -- System Information: Debian Release: testing/unstable APT prefers testing APT policy: (500, 'testing') Architecture: i386 (i686) Shell: /bin/sh linked to /bin/bash Kernel: Linux 2.4.27abi-0.1 Locale: [EMAIL PROTECTED], [EMAIL PROTECTED] (charmap=ISO-8859-15) Versions of packages python-pygresql depends on: ii python 2.3.5-2 An interactive high-level object-o ii python-egenix-mxdatetime 2.0.6-1 date and time handling routines fo ii python2.3-pygresql 1:3.6.1-1 PostgreSQL module for Python -- no debconf information -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]