Package: python-pgsql
Version: 2.4.0-5
Severity: normal
Tags: patch

String representation of a mx.DateTime value having a fractional second 
contains a ',' (comma) if this is the locale's decimal separator. 
An SQL statement containing such a timestamp always fails. 

Another problem is, that the fractional seconds are cut off after the second 
digit (due to str () implementation of mx.DateTime). This renders a timestamp 
column with a default-value of 'NOW ()' unusable since the read value
always differ from what will be issued in an update statement.

For mx.DateTimeDelta values with fractional seconds the fractional part
is completely dropped. This renders time columns unusable since the
value will be changed in the backend (silently). 

The following patch should solve these problems.


--- PgSQL-org.py        2005-07-15 10:44:13.494271208 +0200
+++ PgSQL.py    2005-07-15 11:40:33.595417728 +0200
@@ -2254,7 +2254,8 @@
     elif hasattr(value, '_quote'):
        return value._quote()
     elif type(value) is DateTimeType:
-       return "'%s'" % value
+       return "'%04d-%02d-%02d %02d:%02d:%09.6f'" % (value.year, value.month,
+                           value.day, value.hour, value.minute, value.second)
     elif type(value) is DateTimeDeltaType:
        return "'%s'" % dateTimeDelta2Interval(value)
     elif isinstance(value, StringType):
@@ -2294,18 +2295,11 @@
     """
 
     if type(interval) is DateTimeDeltaType:
-       s = str(interval)
-       ago = ''
-       if s[0] == '-':
-           ago = ' ago'
-           s = s[1:]
-       else:
-           ago = ''
-       s = s.split(':')
-       if len(s) < 4:
-           return '%s:%s:%s %s' % (s[0], s[1], s[2], ago)
-
-       return '%s days %s:%s:%s %s' % (s[0], s[1], s[2], s[3], ago)
+       return ("%s %02d:%02d:%09.6f%s" % ( \
+         interval.day and '%d days' % abs (interval.day) or '',
+         abs (interval.hour), 
+         abs (interval.minute), abs (interval.second),
+         interval.day < 0 and ' ago' or '')).strip ()
     else:
        raise TypeException, "DateTimeDelta2Interval requires a DataTimeDelta."
 


-- 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-pgsql depends on:
ii  python                        2.3.5-2    An interactive high-level object-o
ii  python2.3-pgsql               2.4.0-5    A Python DB-API 2.0 interface to P

-- no debconf information


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to