I tried making 2 functions that use sqlite3 in python but when I run the code the functions would run even when not called.
Whenever I run the program set_prod_ID() would run even though I only called for get_product_ID()
here is my code:
import sqlite3
conn = sqlite3.connect('productList.db')
c = conn.cursor()
def set_prod_ID(prodName=input("Please put product name to be changed: "), idNo=input("Please input new product ID: ")):
conn = sqlite3.connect('productList.db')
c = conn.cursor()
# prodName
# idNo
c.execute("""UPDATE products SET ID = (?)
WHERE NAME = (?)
""", (idNo, prodName))
conn.commit()
conn.close()
def get_product_ID(prodName=input("Please input the Name of the product: ")):
conn = sqlite3.connect('productList.db')
c = conn.cursor()
c.execute("SELECT * from products WHERE NAME = (?)", (prodName,))
items = c.fetchall()
for item in items:
print(item[0])
conn.commit()
conn.close()
get_product_ID()