How to use dates with pysqlite

Otto Tronarp otttr440 at student.liu.se
Mon Mar 31 16:52:20 EST 2003


Hi,

I can't get dates to work with pysqlite. I was under the impression that
it should autmatically cast columns of type date to a mx.DateTime if I
hade mx.DateTime installed. However when I do a select from the database
I always gets a string back. Any ideas of what I do wrong?

Python 2.2.2 (#1, Mar 12 2003, 09:06:07) 
[GCC 3.2.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite
>>> from mx import DateTime
>>> 
>>> con = sqlite.connect('testdb', autocommit=1)
>>> cur = con.cursor()
>>> cur.execute('create table test (d date)')
>>> d = DateTime.Date(2003, 03, 31)
>>> print d
2003-03-31 00:00:00.00
>>> cur.execute('insert into test values(%s)', d)
>>> cur.execute('select * from test')
>>> r = cur.fetchone()
>>> print r
('2003-03-31 00:00:00.00',)
>>> print type(r[0])
<type 'str'>
>>> print type(d)
<type 'DateTime'>
>>> 

I would expect type(r[0]) to return the same as type(d) here.


Otto






More information about the Python-list mailing list