#108 Returns None for selects using date functions

MySQLdb-1.1
closed
Andy Dustman
MySQLdb (285)
5
2012-09-19
2004-10-12
Gordon Tyler
No

All packages installed from Debian unstable on PowerPC:
MySQLdb 1.1.5
MySQL server 4.0.21
Python 2.3.4

mysql> select date_add("2004-01-01", interval 1 year);
+-----------------------------------------+
| date_add("2004-01-01", interval 1 year) |
+-----------------------------------------+
| 2005-01-01 |
+-----------------------------------------+
1 row in set (0.01 sec)

In Python:

c = db.cursor()
c.execute("select date_add('2004-01-01', interval 1
year)")
1L
c.fetchall()
((None,),)

Same thing happens when the date_add function is used
referencing a column. Note that the date value is in
fact valid.

Debian bug#158860

Discussion

  • Andy Dustman
    Andy Dustman
    2004-10-12

    Logged In: YES
    user_id=71372

    Reproduced in 1.1.6.

    Here's what I think the problem is: In MySQL-4.0, date_add()
    returns a DATETIME column type (in the C API), though it
    really should be returning a DATE column (obviously it is
    formatted for DATE). In MySQLdb DATETIME columns are
    converted with DateTime_or_None, and since this is really a
    DATE (with no time), you get None.

    I am inclined to think this is a MySQL bug. However, here is
    a work-around: In MySQLdb.pytimes, change the last line of
    DateTime_or_None() from:

        return None
    

    to:

        return Date_or_None(s)
    

    Let me know if this works for you and I will put it in 1.1.7.

     
  • Gordon Tyler
    Gordon Tyler
    2004-10-14

    Logged In: YES
    user_id=13108

    Once I changed both "return None" statements in that function,
    it worked.

     
  • Andy Dustman
    Andy Dustman
    2004-10-29

    Logged In: YES
    user_id=71372

    This has been fixed in the current CVS tree.