If you declare your column as a timestamp type, you are in clover:
>>> db = sqlite3.connect(':memory:', detect_types=sqlite3.PARSE_DECLTYPES) >>> c = db.cursor() >>> c.execute('create table foo (bar integer, baz timestamp)') <sqlite3.Cursor object at 0x40fc50> >>> c.execute('insert into foo values(?, ?)', (23, datetime.datetime.now())) <sqlite3.Cursor object at 0x40fc50> >>> c.execute('select * from foo') <sqlite3.Cursor object at 0x40fc50> >>> c.fetchall() [(23, datetime.datetime(2009, 12, 1, 19, 31, 1, 40113))]
Cm? both int (for a declared integer) and datetime (for a column declared with a timestamp) survive a round with an intact type.
Alex Martelli Dec 02 '09 at 3:33 2009-12-02 03:33
source share