在使用 mysqldb 这样的库时,可以使用游标来查看数据库发生变化的条目数。
cur = con.cursor ()
cur.execute ("DELETE FROM Writers WHERE created_time <= %s", (datetime,))
numrows = int (cur.rowcount )
那如果是使用 sqlalchemy 的 session 操作数据库呢?
self.session.query (Writer ).filter (Writer.created_time <= datetime,).delete ()
我如何知道到底删了多少条记录?
1
neoblackcap 2015-09-07 16:21:21 +08:00 1
不是会返回一个成功执行的条数么?
|
2
aiqier OP @neoblackcap 谢了啊,搜了半天没搜到。
|
3
zhuangzhuang1988 2015-09-07 23:21:53 +08:00
看下 delete 文档.
:return: the count of rows matched as returned by the database's "row count" feature. http://docs.sqlalchemy.org/en/rel_1_0/orm/query.html#sqlalchemy.orm.query.Query.delete |