Dates always returned as None
MySQL database connector for Python programming
Brought to you by:
adustman
On Mac OS 10.2.6 with mysql 4.0.14 and MySQLdb 0.9.3b1,
every time I do a select query on a datetime field I get None
in it
I do have mx.DateTime installed.
When I use _mysql with the same query i get a string back
which mx.DateTime.ISO.ParseDateTime() copes with fine.
Any ideas why this is failing?
Logged In: NO
I experienced the same with MySQL 4.0.15 and MySQLdb 0.9.3b1 on
Linux (SuSE8.2).
But I compile the extension with Python 2.2.3 and then copy it to use it
with 2.3, but I don't really think this matters here in any way since the
same with MySQLdb 0.9.2 does it just fine (at least for my development)
.
I didn't spent more time into searching the problem, perhaps I will.
cu
jagdfalke
PS @Andy Dustman: keep up the good work and I'm looking forward to
version with supports Python 2.3 :)
Logged In: YES
user_id=139309
I just checked out CVS, pytimes is the culprit, and it causes
MySQLdb (as installed by normally) to be unable to deal with dates
or times (at least in 2.3).
Please write unit tests for pytimes and make it work, or remove it.
mxDateTime actually works, is proven, and more efficient than
pytimes. I don't know why you prefer your unstable buggy
implementation (by way of import order) over mxDateTime.
Logged In: YES
user_id=458828
I can confirm this problem in the following environment:
Solaris 2.6
MySQL 3.23
Python 2.3.2
Logged In: YES
user_id=458828
My problem was resolved by modifying Date_or_None()
in pytimes.py. I replaced
< try:
< return apply(date, tuple(s.split('-',2)))
< except:
< return None
with this:
> year, month, day = s.split('-')
> return date(int(year), int(month), int(day))
What is the reason for the try/except block here? If
there is a specific exception we want to catch, then
we should trap it. Otherwise I'm not in favor of
silently ignoring errors and returning None.
Logged In: YES
user_id=71372
pytimes is only a wrapper around the new datetime module in
Python 2.3. If you don't have datetime, it should use
mx.DateTime, and then failing that, uses some simple
string-based time handling from stringtimes.py. I'm still
shaking out Python 2.3 support.
Logged In: YES
user_id=139309
The problem is that pytimes is broken
Take it out or fix it. It shouldn't be in a release version.
Logged In: YES
user_id=71372
There's a reason it's called DateTime_or_None: If it gets
passed a badly-formatted string, or an illegal DateTime
value, you get back a None. There are (or have been)
conditions in the past where MySQL itself will return
illegal DateTime values. In those cases, you can't fetch the
row from the database, because you get an exception.
I've checked in a change which ought to fix DateTime_or_None
and Date_or_None (covert strings to integers). It's not
tested just yet; I need to get Python-2.3.2 installed.
Logged In: YES
user_id=71372
I believe 0.9.3b3 fixes this. It will also try to use
mx.DateTime first, on the assumption that if you install it
with Python-2.3.x, you probably want to use it instead of
the datetime module. If it's not there, it uses
datetime/pytimes, then stringtimes.
Logged In: YES
user_id=71372
This has been fixed in the current CVS tree.