Re: [SQLObject] DateTimeCol with microsecond resolution.
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Oleg B. <ph...@ph...> - 2011-02-01 18:13:55
|
On Tue, Feb 01, 2011 at 12:26:34PM -0500, Ben Timby wrote: > I really need to store date/time values with millisecond resolution. > What would be the easiest way to achieve this? I found the following > patch: > > http://permalink.gmane.org/gmane.comp.python.sqlobject/5106 > > But I am loath to apply a patch to SQLObject since my code must be portable. You couldn't apply it anyway - it's too old. > Must I create my own column type? Is there any way to override the > storage method of DateTimeCol? I tried passing a datetimeFormat to the > DateTimeCol.__init__() but this did not have the desired effect. I am > assuming the TIMESTAMP data type of sqlite does not support this level > of resolution? If so, I suppose I must store the date as a string in > ISO 8601 format? You don't understand all subtle details of SQLObject (which is ok). The architecture works this way: to convert data to an SQL string column validator's .from_python() method is called, and whatever it returns (including a simple string) is passed to converters (see converters.py). If you want to override datetime converter for all datetime columns - just register your own converter: def DateTimeConverter(value, db): return "'%s'" % value.isoformat registerConverter(datetime.datetime, DateTimeConverter) Oleg. -- Oleg Broytman http://phdru.name/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |