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.

mathieu
  • 107
  • 2
  • 11

1 Answers1

4

Pass additional arguments in a tuple:

xpcounter = "UPDATE CharactersDB SET Exp=%s WHERE %s"
cur.execute(xpcounter, (xp, name,))
monoid
  • 1,661
  • 11
  • 16
  • 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 Jul 06 '13 at 17:01
  • @Mathieu - that's a different problem - see [here](http://stackoverflow.com/questions/4946899/mysql-truncated-incorrect-integer-value) – mata Jul 06 '13 at 17:13
  • thanks, I checked it and it is indeed updating properly. Thanks again! – mathieu Jul 06 '13 at 17:14