1

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()

1 Answer 1

2

The problem is this line:

change = 'UPDATE batch SET ? WHERE ?' (ToThis, ChangeThis)

You're defining a string literal, then trying to call it like a function with the arguments (ToThis, ChangeThis). That's never going to work, since as the exception says, 'str' objects are not callable. There's no need for the parameters to be on that line. Add them instead to the cur.execute() call:

change = 'UPDATE batch SET ? WHERE ?'
cur.execute(change, (ToThis, ChangeThis))

...or just

cur.execute('UPDATE batch SET ? WHERE ?', (ToThis, ChangeThis))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.