cassandra-rs icon indicating copy to clipboard operation
cassandra-rs copied to clipboard

The number of parameters and parameter types not exposed on PreparedStatement

Open pkolaczk opened this issue 3 years ago • 1 comments

I can't find a way to get the number of parameters on a PreparedStatement. Also there is no way to get the actual type of the parameter by name, because the parameter_data_type_by_name returns a ConstDataType which is defined in a private module and not exposed in the public API.

Exposing such information would be useful in all the use-cases where the CQL string is provided by the user or built dynamically, so the types are not known at the time of writing the program and cannot be hardcoded.

pkolaczk avatar Aug 31 '21 17:08 pkolaczk

The first is a limitation of the underlying C++ API. It's not documented, but the driver source code shows that parameter_name returns LIB_INDEX_OUT_OF_BOUNDS if the index is out of bounds, so you could just iterate until you hit that.

You're right that ConstDataType isn't currently exposed. It doesn't look completely trivial; bindgen hasn't managed to expose anything here either in cassandra-sys-rs (cass_prepared_parameter_data_type), so it would require some manual work. Note that the type of a parameter may be a UDT, so it's not a fixed set. I'd be very happy to accept an MR to add something though, and I can provide any design feedback needed.

If built dynamically, you will know the number and types of parameters anyway and not need to query. For the case of user input, all I can suggest is to provide your own DSL to the user, and translate that into CQL internally.

kw217 avatar Sep 01 '21 09:09 kw217