pacman82/odbc-api

Implement string type output parameters for queries

Closed this issue · 4 comments

Please implement Pod and other required impl's for string CDatatypes Char and WChar. There are outputs for numeric types, but none for string-based types.

Hello @TylerJMcLean ,

thing is a String is not Pod. These are variadic types, which means we do not know how big they are in memory. Best way to fetch them is using a columnar buffer. See the documentation on how to fetch values: https://docs.rs/odbc-api/latest/odbc_api/buffers/struct.ColumnarBuffer.html

If you want to fetch your data row wise, and know your table schema at compile time, you can also use RowVec and use the derive feature.

See: https://docs.rs/odbc-api-derive/latest/odbc_api_derive/derive.Fetch.html

Hey @pacman82, I ended up figuring that out after another half an hour of digging through the project and meant to come back to close this.

It was not clear to me while reading through the documentation that I could do something like the following with out parameters to obtain a string

let mut out_msg: VarWCharArray<21> = VarWCharArray::NULL;

connection.execute("CALL PROCEDURE_NAME(?)", (Out(&mut out_msg),))?; 

as the only example that was available used Nullable's exclusively here. Perhaps the example should be updated to reflect this? Regardless I will close this ticket as my issue is resolved. Thanks for the quick reply!

Hello @TylerJMcLean ,

I am happy you did not close the issue immediately. Improving can bring just as much value as improving the code. I clarified the documentation of Out and added an example to VarCharArray.

Best, Markus