【问题标题】:cassandra python driver bind to intcassandra python驱动绑定到int
【发布时间】:2015-06-10 10:08:55
【问题描述】:

我正在为 python 使用 datastax 驱动程序。似乎preparedstatement 不能绑定到int 输入?

item_by_user1 = session.execute(item_by_user_lookup_stmt.bind(int(123)))

它转储错误消息 TypeError: 'int' 类型的对象没有 len()

python 驱动程序是否仅限于使用文本字段?

【问题讨论】:

    标签: python cassandra prepared-statement


    【解决方案1】:

    您需要绑定一个包含 Int 的元组,而不仅仅是一个 int。 has no len() 错误是由驱动程序试图计算绑定参数中有多少元素引起的。由于绑定参数是一个 int,它不能调用 len() 并引发错误。

    item_by_user1 = session.execute(item_by_user_lookup_stmt.bind((int(123),)))
                                                                  ^         ^
    

    为什么我们需要 , 因为 python 中的元组语法, https://wiki.python.org/moin/TupleSyntax

    【讨论】:

      猜你喜欢
      • 2017-08-22
      • 2018-08-28
      • 2017-08-07
      • 1970-01-01
      • 2015-04-12
      • 2017-11-26
      • 2018-06-15
      • 2018-11-10
      • 1970-01-01
      相关资源
      最近更新 更多