I created a database and got it working as far as searching for a specific batchnr. what i would like to do is as follows:
input batchnumber:1001
It will give me the following result:
(1001, 90, 10001, 2, 500, 'Veghel', 100, 300)
Then the following question gets asked: "would you like to change something about this"
The value you want to change is stored in "ChangeThis" and the value you want it to be changed in is stored in "ToThis" (had to translate it to english so thats why it's pretty basic)
For example you will get something like this:
(1001, 90, 10001, 2, 500, 'Veghel', 100, 300)
change what: 500
into: 9999
Now I want to put these variables into my python-SQL code i tried this:
conn = sqlite3.connect('DATABASE.db')
cur = conn.cursor()
ChangeThis = str(input("which value would you like to change?(value):"))
ToThis = str(input("In what would you like to change this?(value):"))
change = 'UPDATE batch SET ? WHERE ?' (ToThis, ChangeThis)
print(change)
cur.execute(change)
This gives me the TypeError: 'str' object is not callable.
Does anyone have an idea how to fix this?
full code is posted below:
import sqlite3
def create_connection():
try:
conn = sqlite3.connect('DATABASE.db')
return conn
except Error as e:
print(e)
def select_all():
conn = sqlite3.connect('DATABASE.db')
cur = conn.cursor()
batchnr = input("batchnumber:")
sqlquery = 'SELECT * FROM BATCH WHERE BATCHNR ='+ batchnr
#print(sqlquery)
cur.execute(sqlquery)
rows = cur.fetchall()
for row in rows:
print(row)
verander = input("Would you like to change something about this?Y/N: ")
if verander == 'Y' or verander == 'y':
veranderen()
else:
print("Shutdown")
def veranderen():
conn = sqlite3.connect('DATABASE.db')
cur = conn.cursor()
ChangeThis = str(input("which value would you like to change?(value):"))
ToThis = str(input("In what would you like to change this?(value):"))
change = 'UPDATE batch SET ? WHERE ?' (ToThis, ChangeThis)
print(change)
cur.execute(change)
create_connection()
select_all()