zoit
zoit

Reputation: 667

Errors updating a record in Python

I am trying to do a simple update in python. This the code I try to run:

 mycursor = mydb.cursor()
 if(result<5):
        os.remove(destiny)
        print(result)
        print(fi[:-4])
        print(lastid)
        sql = "UPDATE googlesearch SET similarity=%s WHERE tweetid=%d and imageName=%s"
        value = (str(result),lastid,str(fi[:-4]))
        print(value)
        mycursor.execute(sql, value)
        mydb.commit()

As you can see it is very easy. But when I run it, I have this error:

ProgrammingError: Not all parameters were used in the SQL statement

Printing values, I have this: ('2.82258064516129', 2636, 'dimg_10') And working in Navicat with this sentence, everything is perfect. So why, I have this error?.

Upvotes: 1

Views: 41

Answers (1)

khelwood
khelwood

Reputation: 59112

Statement parameter positions are indicated by %s, not %d.

So I think if you change

sql = "UPDATE googlesearch SET similarity=%s WHERE tweetid=%d and imageName=%s"
                                                            ^

to

sql = "UPDATE googlesearch SET similarity=%s WHERE tweetid=%s and imageName=%s"
                                                            ^

you will avoid this error.

Upvotes: 1

Related Questions