bug fix for pyPgSQL 2.4
Karsten Hilbert <[email protected]> Tue, 17 Jan 2006 19:36:36 +0100
| Newsgroups | gmane.comp.python.db.pypgsql.user |
|---|---|
| Message-ID | <[email protected]> |
--YZ5djTAD1cGYuMQK
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Hi all,
we are using pyPgSQL with GNUmed.
When storing a PgDateTime instance (an mx.DateTime
instance, that is) the _quote() function does
"'%s'" % value
Which in turn calls value.__str__().
Wich does the following to its seconds value:
"%02.5f" % self.seconds
In some locales (namely where the decimal separator is
something other than a ".") this will produce (for example)
"25,12"
instead of
"25.12"
for 25 seconds 120 milliseconds
Now, PostgreSQL (properly ?) does not accept "xx,yy" as a
valid timestamp string.
Attached find a crude hack overcoming this problem.
The proper fix would be to make pyPgSQL *force* mx.DateTime to
deliver a valid format via value.Format('...') or some such.
Karsten
--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346
--YZ5djTAD1cGYuMQK
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="pyPgSQL-timestamp-locale-fixup.diff"
--- PgSQL.py.original 2005-06-20 18:02:39.000000000 +0200
+++ PgSQL.py 2006-01-17 18:37:25.000000000 +0100
@@ -2254,7 +2254,12 @@
elif hasattr(value, '_quote'):
return value._quote()
elif type(value) is DateTimeType:
- return "'%s'" % value
+ val = "'%s'" % value
+ # the real fix would be to use value.Format() but getting
+ # the proper timezone information may be tricky,
+ # so, this is a hack
+ val = val.replace(",", ".")
+ return val
elif type(value) is DateTimeDeltaType:
return "'%s'" % dateTimeDelta2Interval(value)
elif isinstance(value, StringType):
--YZ5djTAD1cGYuMQK--
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642