Re: Problem with locale and psycopg2

dick <dickkniep-nI4mw7d/IixmR6Xm/[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Organization Lindix
Message-ID <[email protected]>
Hi Karsten,

Thanks a lot for your solution. I will use this 

Cheers,
Dick


Op zondag 30 augustus 2009 16:04:06 schreef Karsten Hilbert:
> On Sun, Aug 30, 2009 at 01:37:39PM +0200, dick wrote:
> > We are porting a big application that still uses psycopg1 to psycopg2.
> >
> > Now I encountered the following problem with locales and storing of time:
> >
> > invalid input syntax for type time: "09:00:00,000000"
> >
> > You may notice the comma (,) in front of the millisecond part. Now I have
> > seen this problem in the past (2006) with a slightly different form
> > (timestamp), but off course it should (depending on the locale) accept
> > this time as valid!
>
> It is annoying and ultimately a failure of PostgreSQL which
> I did report there, too. GNUmed solves it like this:
>
> class cAdapterMxDateTime(object):
>
> 	def __init__(self, dt):
> 		self.__dt = dt
>
> 	def getquoted(self):
> 		# under some locale settings the mx.DateTime ISO formatter
> 		# will insert "," into the ISO string,
> 		# while this is allowed per the ISO8601 spec PostgreSQL
> 		# cannot currently handle that,
> 		# so map those "," to "." to make things work:
> 		return mxDT.ISO.str(self.__dt).replace(',', '.')
>
> try:
> 	import mx.DateTime as mxDT
> 	psycopg2.extensions.register_adapter(mxDT.DateTimeType,
> cAdapterMxDateTime) except ImportError:
> 	_log.warning('cannot import mx.DateTime')
>
>
> Karsten

-- 
Met vriendelijke groet,
Dick Kniep
tel.     036-5343830
mob.  06-50991858

_______________________________________________
Psycopg mailing list
Psycopg-IAPFreCvJWPBWskQ1e/[email protected]
http://lists.initd.org/mailman/listinfo/psycopg
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.