I would like to be able to assign a variable from a SQLite table entry I have, I need to be able to get the QTY of the part_no which will be entered by the user. So the user enters a part number, it then searches the database for the part number, once found assigns a variable with the QTY from the qty column for the searched part.
My table set up is below...
db = sqlite3.connect('db.sqlite3')
cursor = db.cursor()
# Table creation
cursor.execute('''
CREATE TABLE IF NOT EXISTS spares(
id INTEGER PRIMARY KEY,
part_no TEXT,
desc TEXT,
qty NUM,
rack TEXT,
shelf TEXT)
''')
db.commit()
I'm unsure on how to write the SQL command to do this or if if can be done at all?
What I have done so far is the below, but this does not grab the qty which I need!
selection = askstring('Please enter your Part Number:)
cursor.execute("SELECT * FROM spares WHERE part_no LIKE '%' || ? || '%'", (selection,))
The above returns the searched part number row, but now how do I set a variable with the QTY entry for that part number?
The reason for been able to do this is so I can do math on the qty to either + or - the entry.
Thanks in advance as always :)