【问题标题】:calling select query after update query with flask-sqlalchemy db.engine.execute() returns un-updated resultset在使用 flask-sqlalchemy db.engine.execute() 更新查询后调用选择查询返回未更新的结果集
【发布时间】:2021-12-01 02:16:17
【问题描述】:

在使用 flask-sqlalchemy db.engine.execute() 更新查询后调用选择查询返回未更新的结果集。

我有一个 python 项目,我正在从 flask-sqlalchemy 更新 MySQL 表中的一行 db.engine.execute() 函数,然后在下一行我正在对同一行进行 select 查询并将其作为响应发送到前端。但是选定的查询会结束同一行的旧数据,当我检查数据库中的行时,它实际上是更新的。据我所知,像 MySQL 这样的关系数据库在事务中具有一致性(ACID 属性),这里没有显示。

请指导我哪里做错了。

        else:
            name = "yoga" if name is None else name
            stmt = (update(Combination)
                    .values(name=name,description=description,result=result, quality=quality, flag=flag)
                    .where((Combination.sequence == sequence) & (Combination.subseq == subseq) & (Combination.languageId == lang_id) ))
        try:
            cur.execute(stmt)
            combination = Combination.query.filter(Combination.sequence == sequence, Combination.languageId == lang_id).first()
            res['status'] = 'success'
            res["flag"] = combination.flag
            res["name"] = combination.name
            res["description"] = combination.description
            res["result"] = combination.result
            res['quality'] = combination.quality
            res['language_id'] = lang_id
        except exc.SQLAlchemyError:
            res['status'] = 'failed'
        return res

【问题讨论】:

    标签: python mysql flask sqlalchemy flask-sqlalchemy


    【解决方案1】:

    执行你的语句后提交呢?

    添加:

    cur.commit()
    

    之后:

    cur.execute(stmt)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-03
      • 2021-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 2015-09-04
      相关资源
      最近更新 更多