samedi 12 septembre 2015

Sqlite/Python simple issue when searching DB

Hello I am having a bit of a dumbo problem. I am trying to search a DB for an ID number. The problem I am running into in when I enter a ID number that does not exist the program crashes. I will post my code under and try to explain where I am at. I am using SQlite with Python3.

cur = con.cursor()

cur.execute("SELECT * FROM coupons WHERE id_num=:id_num",
    {"id_num": input_value})
con.commit()
row = cur.fetchone()

#Verifying that the ID exists for later in the program. 
if input_value == row[0]:
    bad_code = False

I know my programming is somewhat amateurish but I am still learning the ropes.

The error is as follows:

Traceback (most recent call last):
File "Z:/Python_Programs/data_bases/coupon_scanner_v8.py", line 217, in      <module>
verify_barcode(user_code);
 File "Z:/Python_Programs/data_bases/coupon_scanner_v8.py", line 87, in verify_barcode
startDay = row[1]
TypeError: 'NoneType' object is not subscriptable

I will continue to do research to solve this probelm. Thank you!!!

Aucun commentaire:

Enregistrer un commentaire