1

I've searched around but it looks like most people with a similar question have two strings on one SQL variable, whereas I have two different arguments.

My code:

xpcounter = ("UPDATE CharactersDB SET Exp=%s WHERE %s", xp, name) #where is name variable
cur.execute(*xpcounter)

I have also tried:

xpcounter = ("UPDATE CharactersDB SET Exp=%s WHERE %s") #where is name variable
cur.execute(xpcounter, xp, name)

both times I get a

TypeError: execute() takes at most 3 arguments (4 given)

What am I doing wrong?

Thanks!

EDIT: As per monoid's suggestion, my code now looks like:

xpcounter = ("UPDATE CharactersDB SET Exp=%s WHERE %s", (xp, name,)) cur.execute(*xpcounter)

Now I get a

Truncated incorrect INTEGER value: 'testname'

when I run it.

EDIT: Turns out my database is updating correctly, just a warning, not an error.

1 Answer 1

4

Pass additional arguments in a tuple:

xpcounter = "UPDATE CharactersDB SET Exp=%s WHERE %s"
cur.execute(xpcounter, (xp, name,))
Sign up to request clarification or add additional context in comments.

3 Comments

Awesome, thank you so much! EDIT: Well, now it gives a "Truncated incorrect INTEGER value:" when I enter a name. I assume (I'm still very new to coding) that it's trying to convert a string to an integer?
@Mathieu - that's a different problem - see here
thanks, I checked it and it is indeed updating properly. Thanks again!

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.