Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The number of parameters and parameter types not exposed on PreparedStatement #124

Open
pkolaczk opened this issue Aug 31, 2021 · 1 comment

Comments

@pkolaczk
Copy link

pkolaczk commented Aug 31, 2021

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.

@kw217
Copy link
Collaborator

kw217 commented Sep 1, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants