[CentOS] Python/sqlite date time problems.

Tue Oct 10 14:59:42 UTC 2006
Will McDonald <wmcdonald at gmail.com>

Bear with me, this is CentOS related. :)

I have a python CGI that's behaving weirldy on Whitebox systems
that've been switched over to CentOS 4 (ages ago, no other problems to
speak of aside from this one).

I've broken the problem down to a minimal test case...

1. Create a small database

# sqlite3 /tmp/testcase.db 'CREATE TABLE testtable ( date date primary
key unique, name varchar(32));'
# sqlite3 /tmp/testcase.db 'insert into "testtable"
values("2006-10-10", "Will");'
# sqlite3 /tmp/testcase.db 'insert into "testtable"
values("2006-10-11", "Will");'

2. A small Python script to query this database:

#!/usr/bin/python

import sqlite

cx = sqlite.connect('/tmp/testcase.db')
cu = cx.cursor()
cu.execute("select date from %s where date like '%s' ;" %
('testtable', '2006-10-' + "%"))
print cu.fetchall()
## -------------------- END SCRIPT -------------------- ##

Now, here's what's confusing me. If I run this on a box that was built
from scratch with CentOS I get the following data back...

[root at willspc python]# ./testcase.py
[('2006-10-10',), ('2006-10-11',)]

If I run it on any upgraded Whitebox system I get...

[root at devmon1 python]# ./testcase.py
[(<DateTime object for '2006-10-10 00:00:00.00' at b7f14138>,),
(<DateTime object for '2006-10-11 00:00:00.00' at b7cbfdb0>,)]

As far as I can tell, python, sqlite and python-sqlite are all identical.

[root at willspc python]# rpm -qa | grep -Ei '(sqlite)|(python)' | sort
libxml2-python-2.6.16-6
mod_python-3.1.3-5.1
python-2.3.4-14.2
python-elementtree-1.2.6-4.2.1
python-sqlite-1.1.7-1.2
python-urlgrabber-2.9.8-2
rpm-python-4.3.3-18_nonptl
sqlite-3.3.3-1.2

On the upgraded system...

[root at devmon1 python]# rpm -qa | grep -Ei '(sqlite)|(python)' | sort
libxml2-python-2.6.16-6
mod_python-3.1.3-5.1
MySQL-python-1.0.0-1.RHEL4.1
python-2.3.4-14.2
python-clearsilver-0.10.1-1.2.el4.rf
python-elementtree-1.2.6-7.el4.rf
python-sqlite-1.1.7-1.2
python-urlgrabber-2.9.8-2
rpm-python-4.3.3-18_nonptl
sqlite-3.3.3-1.2
sqlite-devel-3.3.3-1.2

Obviously there some date/time issues but I can't pinpoint exactly
what. Can anyone shed any light or prod me in the right direction? The
Whitebox systems *do* still have a smattering of Whitebox related
RPMs...

[root at devmon1 python]# rpm -qa | grep white
rpmdb-whitebox-4-0.20050504
whitebox-logos-1.1.25-1.WB1

That system did have whitebox-lsb installed too but I've rpm -e'd it
and replaced redhat-lsb, haven't rebooted yet but that's next on the
agenda.

Cheers.

Will.