简体   繁体   English

Peewee和更新

[英]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 . 让我们说虽然我实际上没有一个等于teamsagarin_name Is there any way to see if 0 rows were updated. 有没有办法查看是否更新了0行。 I see on the Peewee doc page, that doing updates right into IDLE returns the rows that were updated. 我在Peewee文档页面上看到,对IDLE进行更新将返回已更新的行。 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中使用sqlite。

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 缺省情况下,peewee更新查询返回未更新结果的计数,存储execute语句的输出,并根据需要在语句后使用

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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