bhomass
bhomass

Reputation: 3572

cassandra python driver bind to int

I am using the datastax driver for python. It seems the preparedstatement can not bind to an int input?

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

it dumps the error message TypeError: object of type 'int' has no len()

Is python driver restricted to work with text fields only?

Upvotes: 1

Views: 618

Answers (1)

RussS
RussS

Reputation: 16576

You need to bind a tuple containing an Int, not just an int. The has no len() error is caused by the driver trying to count how many elements are in bind parameter. Since the bind parameter is is an int it can't call len() and throws an error.

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

Why do we need the , because of tuple syntax in python, https://wiki.python.org/moin/TupleSyntax

Upvotes: 4

Related Questions