Python Forum
Help with subtracting values using SQLite & Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with subtracting values using SQLite & Python
#11
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]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  need help with data analysing with python and sqlite Hardcool 2 369 Jan-30-2024, 06:49 AM
Last Post: Athi
  python sqlite autoincrement in primary column janeik 6 1,161 Aug-13-2023, 11:22 AM
Last Post: janeik
  [Solved]Help with search statement-SQLite & Python Extra 1 1,057 May-06-2022, 07:38 PM
Last Post: Extra
  Help With Python SQLite Error Extra 10 15,076 May-04-2022, 11:42 PM
Last Post: Extra
  Python Sqlite georgebijum 0 1,057 May-04-2022, 10:12 AM
Last Post: georgebijum
  Subtracting datetimes [index] Mark17 2 2,483 Aug-21-2021, 12:11 AM
Last Post: Larz60+
  Importing data from a text file into an SQLite database with Python macieju1974 7 4,145 Jun-29-2020, 08:51 PM
Last Post: buran
  Inserting values from multiple lists sqlite azulu 1 2,511 May-24-2020, 08:40 AM
Last Post: ibreeden
  how to use items combobox in table name sqlite in python hampython 1 2,695 May-24-2020, 02:17 AM
Last Post: Larz60+
  Indexing problem while iterating list and subtracting lbtdne 2 2,138 May-14-2020, 10:19 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020