Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datetime fields with microsecond shows as None (SF bug #325) #24

Closed
tyzhnenko opened this issue Jul 15, 2013 · 4 comments
Closed

Datetime fields with microsecond shows as None (SF bug #325) #24

tyzhnenko opened this issue Jul 15, 2013 · 4 comments

Comments

@tyzhnenko
Copy link
Contributor

Original bug on https://sourceforge.net/p/mysql-python/bugs/325/

When SELECT datatime field which contained microseconds from DB(MariaDB 5.5 and MySQL 5.6). Result can not be converted to datetime.datetime and data in that field shows as None. I use MariaDB 5.5.27.

For example:
Make table in DB and fill its

import MySQLdb
db=MySQLdb.connect(host="localhost",user="test",passwd="test",db="test")
c=db.cursor()
c.execure("""DROP TABLE IF EXISTS `t1`""")
c.execure("""CREATE TABLE `t1` (
  `id` int(11)
  `date` datatime(6) NOT NULL,
  PRIMARY KEY (`id`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8""")
c.execure("""INSERT INTO t1 VALUES(1,now(6)), VALUES(2,NOW(6)), VALUES(3,NOW(6))""")

Now we can get data.

c.execute("""SELECT * FROM t1""")
r = c.fetchall()
print r

OUT:
((1L, None), (2L, None), (3L, None))

After patch:

c.execute("""SELECT * FROM t1""")
r = c.fetchall()
print r

OUT:
((1L, datetime.datetime(2012, 10, 3, 10, 56, 47, 800462)), (2L, datetime.datetime(2012, 10, 3, 10, 56, 47, 800462)), (3L, datetime.datetime(2012, 10, 3, 10, 56, 47, 800462)))
farcepest added a commit that referenced this issue Aug 18, 2013
Fix problem in Datetime with microsecond returns (Issue #24)
claudep added a commit to claudep/django that referenced this issue Oct 28, 2014
On MySQLdb < 1.2.5, MySQLdb returns None when fetching datetime/time
values with fractional seconds.
See farcepest/MySQLdb1#24
claudep added a commit to django/django that referenced this issue Oct 28, 2014
On MySQLdb < 1.2.5, MySQLdb returns None when fetching datetime/time
values with fractional seconds.
See farcepest/MySQLdb1#24
@lfyzjck
Copy link

lfyzjck commented Jun 29, 2016

Sorry, i still have the issue on version 1.2.5

MySQL Server: 5.6.24 Homebrew
MySQL-python: 1.2.5

Here is my table schema:

CREATE TABLE `app` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, 
`name` varchar(120) NOT NULL UNIQUE, 
`is_deleted` bool NOT NULL, 
`created` datetime(6) NOT NULL, 
`updated` datetime(6) NOT NULL
);

Test Code:

import MySQLdb
db=MySQLdb.connect(host="localhost",user="test",passwd="test",db="test")
c=db.cursor()
c.execute('select * from app')
c.fetchall()

Output:

((1L, 'test1', 0, None, None), (2L, 'test2', 0, None, None))

And the datetime value shows well in mysql shell.

@methane
Copy link
Collaborator

methane commented Jun 29, 2016

@lfyzjck
https://pypi.python.org/pypi/mysqlclient fixed this issue long ago.

@lfyzjck
Copy link

lfyzjck commented Jun 30, 2016

@methane It works, thank you very much!

But why MySQLdb don't fix this issue? it seems very critical.

@methane
Copy link
Collaborator

methane commented Jun 30, 2016

The author is inactive for these years.
Look commit log.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants