Your message dated Fri, 05 Jan 2024 12:16:16 +0000 with message-id <[email protected]> and subject line Re: python-pygresql: handling of datetime values has caused the Debian Bug report #318428, regarding python-pygresql: handling of datetime values to be marked as done.
This means that you claim that the problem has been dealt with. If this is not the case it is now your responsibility to reopen the Bug report if necessary, and/or fix the problem forthwith. (NB: If you are a system administrator and have no idea what this message is talking about, this may indicate a serious mail system misconfiguration somewhere. Please contact [email protected] immediately.) -- 318428: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=318428 Debian Bug Tracking System Contact [email protected] with problems
--- Begin Message ---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: LANG=de_AT@euro, LC_CTYPE=de_AT@euro (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
--- End Message ---
--- Begin Message ---Version: 1:6.0-1 This bug is no longer applicable since the python2 module is no longer packaged. Please feel free to re-open if you are still able to reproduce this bug. Best regards, Dale Richards
--- End Message ---

