Hi.
Using:
- Python 3.2.3
- PyMySQL 0.5
- MySQL 5.5.22-0Ubuntu1
Python 3 script:
import pymysql
yr = int(input("What year? (choose 1980-2012) "))
sql = "SELECT artist,title,heard FROM favsongs WHERE year(heard)=" + str(yr)
conn = pymysql.connect(host='localhost', port=3306, user='myself', passwd='blahblahblah', db='musicfavs')
cur = conn.cursor()
cur.execute(sql)
for r in cur.fetchall():
print(r)
cur.close()
conn.close()
# end of Python script
MySQL table description:
+----------+-----------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-----------------------+------+-----+---------+----------------+
| id | bigint(100) unsigned | NO | PRI | NULL | auto_increment |
| own | tinyint(1) | NO | | 0 | |
| heard | datetime | NO | | NULL | |
| station | varchar(12) | NO | | NULL | |
| released | date | NO | | NULL | |
| artist | varchar(255) | NO | | NULL | |
| title | varchar(255) | NO | | NULL | |
| notes | tinytext | NO | | NULL | |
+----------+-----------------------+------+-----+---------+----------------+
The script returns everything fine except for the datetime field, which PyMySQL always returns as 'None' even though as date & time exist. I've narrowed down the issue to MySQL's time field, even tho I'm using datetime, 'cause I found that the following works for extracting the date in pieces from the datetime field:
SELECT artist,title,year(heard),month(heard),day(heard) FROM favsongs WHERE year(heard)=
But if I add `time(heard)`, then PyMySQL will return `datetime.timedelta(0)` instead of the actual time.
I consider this a very serious bug, since it completely stops me from being able to use PyMySQL, and that likely means it's blocking other people from using it too. None of the other python-to-MySQL modules want to install on my system, so I'm stuck 'til this bug is fixed.
Hi.
Using:
Python 3 script: