diwuqin
V2EX  ›  问与答

用原生 sql 查询 mysql 数据库时,传参老是报错

  •  
  •   diwuqin · Apr 17, 2019 · 1689 views
    This topic created in 2606 days ago, the information mentioned may be changed or developed.

    def user_query(user, table_dict): # 单个用户查询查询数量 try: sql = """SELECT COUNT(id), COUNT(call_result), SUM(hold_time) FROM call_detail WHERE call_result = 'connect' and user_detail_id = {0}; """.format(user[0]) import pdb; pdb.set_trace() print(sql) count_list = db.session.execute(sql) print(count_list) except Exception as e: current_app.logger.error(e) return jsonify(errno=RET.DBERR, errmsg="查询历史号码对象列表异常")

       # user[0]是传过来的一个整数
       ERROR:info:'int' object is not subscriptable			# 查询老是报这句错误, 求大神指教
    
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2534 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 15:50 · PVG 23:50 · LAX 08:50 · JFK 11:50
    ♥ Do have faith in what you're doing.