代码之家  ›  专栏  ›  技术社区  ›  Paul Slater

SQLite3第二次查询的绑定数不正确

  •  0
  • Paul Slater  · 技术社区  · 5 年前

            print("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv")
            print("SQL and parameters:",sql,parm)
            c.execute(sql,parm)
            # Get the row
            print("Executed OK")
            response = c.fetchone()
            # If not successful return null
            if not response:
                return None
            #
            print("and produced ", response)
            print("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^")
    

    给出以下输出:

    vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    SQL and parameters: select * from Links where LinkNum = ? (301,)
    Executed OK
    and produced  (301, 'Index', 'The Independent', 'https://www.independent.co.uk/', 6, 0)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    SQL and parameters: select * from Links where LinkNum = ? (301,)
    Encountered exception of type ProgrammingError with arguments ('Incorrect number of bindings supplied. The current statement uses 1, and there are 6 supplied.',)
    
    The application will close
    

    0 回复  |  直到 5 年前
        1
  •  0
  •   Paul Slater    5 年前

    不管是什么原因导致SQLite出现问题,我都通过检索Links对象外部的第二行/对象,并将其作为参数传递给我调用的方法,而不是让该方法尝试检索该对象来解决这个问题。

    问题仍然存在,但必须深入到Python实例化和/或SQLite的内部。不管怎样,这个问题是用一些不那么花哨的代码解决的。