dimanche 28 février 2016

Python - None returned by using cursor.fetchone()

Internet searches have told me to use cursor.fetchone() as a way to get a particular row from an SQL database in python. But when I use it, I get a None. I'm pretty sure there is stuff in there, so I'm confused about why this is happening. Here is some code

db = sqlite3.connect('dataset.db')
curs = db.cursor()
curs.execute("CREATE TABLE data(id INTEGER PRIMARY KEY, dataObj REAL)")

sqlQuery = "SELECT dataObj FROM data WHERE id = ?"
curs.execute('''INSERT INTO data(dataObj) VALUES (?)''', (info, )) #this is how I add stuff into the table
num = 1
result = curs.execute(sql, (num, )).fetchone()  #should return row from data table
print result  #returns None

I feel like I'm doing something dumb, so sorry if it's something easy.

Aucun commentaire:

Enregistrer un commentaire