简体   繁体   中英

Python SQLite: Update Statement TypeError: function takes exactly 2 arguments (1 given)

For some reason I keep getting a

findSenGroup = cur.executemany("UPDATE SEN_Table SET SenNumber = " + senNumStr + " WHERE FormName='" + nameGroup + "'")

TypeError: function takes exactly 2 arguments (1 given) error

with this update statement:

findSenGroup = cur.executemany("UPDATE SEN_Table SET SenNumber = " + senNumStr + " WHERE FormGroup='" + nameGroup + "'")

Table shown below

在此处输入图片说明

senNumStr is a the number that i want to update a column to.

nameGroup is the name of the row of where I want senNumStr added tp

`````

I'm not sure you need to use executemany here when you're only executing a single statement. You could use simply:

cur.execute("UPDATE SEN_Table SET SenNumber = " + senNumStr + " WHERE FormName='" + nameGroup + "'")

It would be better to use a parameterised query rather than a formatted string though, to avoid SQL injection vulnerabilities:

cur.execute("UPDATE SEN_Table SET SenNumber = ? WHERE FormName = ?", (senNumStr, nameGroup))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM