简体   繁体   中英

Why is this sqlite3 UPDATE giving a syntax error?

I have a function that drops some tables and reinitializes a new set which are working fine, then when it updates the existing table with the following:

self.cursor.execute('''UPDATE beers1 SET (beer_name, og, fg, beer_desc, ibu, glass_type, keg_size) 
    VALUES (?,?,?,?,?,?,?) where id=1''',("Beer", 1, 1, "Delicious!", 0, "Pint Glass", 640))

Which then gives me:

OperationalError: near "(": syntax error

Any insight would be incredibly helpful. Thanks!

The standard SQL syntax for an UPDATE statement is either:

UPDATE beers1
   SET (beer_name, og, fg, beer_desc, ibu, glass_type, keg_size) =
       (?, ?, ?, ?, ?, ?, ?)
 WHERE id = 1

Or:

UPDATE beers1
   SET beer_name = ?, og = ?, fg = ?,
       beer_desc = ?, ibu = ?, glass_type = ?, keg_size = ?
 WHERE id = 1

You will need to check the SQLite3 manual to see which is supported by SQLite3. The second is almost guaranteed to be supported; the first may not be.

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