简体   繁体   中英

Peewee and Updates

How do I know if a record was in fact updated? Here is my code:

for team, rating in team_ratings.items():
      query1 = Ratings.update(sagarin_rating=rating).where(Ratings.sagarin_name == team)
      query1.execute()

Lets say though that I don't actually have a sagarin_name that equals team . Is there any way to see if 0 rows were updated. I see on the Peewee doc page, that doing updates right into IDLE returns the rows that were updated. But how can I capture if any rows updated into a variable?

I need to be able to test if the record was updated or not. Using sqlite with Peewee.

peewee update query by default returns count of no of results updated, store the output of execute statement and use it following statements as needed

for team, rating in team_ratings.items():
      query1 = Ratings.update(sagarin_rating=rating).where(Ratings.sagarin_name == team)
      no_of_row_updated = query1.execute()
      print no_of_row_updated

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