0

I read a bunch of posts about this, couldn't make it work here though (apologies in advance)

(Python version 3.7.0) I have a SQLite3 database:

cursor.execute("""CREATE TABLE everyone(NAME text primary key, ROLE text, SECTION text, USED text)""")

The data looks like this in the table:

enter image description here

I'm pulling x amount of names at random, where Role = FLM

results = cursor.fetchall()
for i in range(3):
    names = secure_random.choice(results)
    print(f'{names}')

This gives me the names I want, and when I print I see:

('Joe Blow 12345',)

I now want to delete Joe Blow from the list completely, OR enter something in the "Used" field (which is just a work around because I couldn't seem to delete)

Here's my code containing the selection of people, and my attempt to update:

results = cursor.fetchall()
for i in range(3):
    names = secure_random.choice(results)
    print(f'{names}')
    #try:
        #cursor.execute(f'''UPDATE everyone SET USED = "Y" WHERE NAME = {names} ''')
    #except:
        #print('Something went wrong updating names in the database.')
    try:
        execute('''UPDATE everyone SET USED = ? WHERE NAME = ?''', (used_var, names))
    except:
        print('Something went wrong updating names in the database.')
        break

No matter how I try this, I can't get it right.

For this: cursor.execute('''UPDATE everyone SET USED = ? WHERE NAME = ?''', (used_var, names))

I get "InterfaceError: Error binding parameter 1 - probably unsupported type."

For this: cursor.execute(f'''UPDATE everyone SET USED = "Y" WHERE NAME = {names} ''')

I get "OperationalError: near ")": syntax error"

I didn't think to record all of the different ways I've tried, I'd really appreciate some help!

1
  • What is used_var? Commented Jun 16, 2022 at 3:08

1 Answer 1

0

Quotations around my f-string variable in the update line fixed this right up for me

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.