Python Forum

Full Version: Help with subtracting values using SQLite & Python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Well done, Extra. You found a good workaround.
But you missed the hint provided by @ndc85430 : Is it a tuple with one item inside?. In this kind of puzzles I always add a "print()" statement before the line with the error to see what the value is. In this case you would have seen "fetchone()" returned a tuple. (Just as the error message stated.) A tuple with one item: the value you wanted. Had you executed something like "SELECT Quantity, ID FROM ..." the tuple would have had two items.
And "fetchall()" returns a list of tuples.
So in the first version of your program you could have solved it with:
#Get current Item quantity by ID
    cursor.execute("SELECT Quantity FROM items WHERE ID = ?",(userQueryID,))
    myrecord = cursor.fetchall()
    currentQuantity = myrecord[0][0]
Pages: 1 2