'using iodbc in Rust
I'm trying to connect to FileMaker through a Rust application (don't ask me why...) - and I run into the wall of the FM ODBC driver being built against iodbc and not unixodbc, but all the ODBC crates I find are using unixodbc.
I'm not too familiar with the lower level stuff around cargo, so I have no idea if and how I can make the Rust odbc crates link against iodbc instead of unixodbc. I asked Google but came up empty.
Can I force cargo to link against a specific library (both unixodbc and iodbc are present on the system, but unixodbc seems to be always picked by default) ?
Solution 1:[1]
Disclosure: I am the owner of the odbc-api
and odbc-sys
crate.
You can use iodbc from Rust, but you must enable the iodbc
feature flag in your Cargo.toml
.
[dependencies]
odbc-api = { version = "0.40.1", features = ["iodbc"] }
Setting this flag achieves three things:
Your applications links against libiodbc.so
rather than libodbc.so
.
Without that you you would get a linker error indicating that -lodbc
is not found.
Your application uses the 3.5 standard of ODBC.
... and declares the ODBC version to be 3.0.
iODBC currently only supports version 3.5. If your application would use ODBC 3.8 it would fail to create an ODBC Environment. The iodbc driver manager does not return any error in this case. It just fails.
Your application uses narrow (Utf-8) function calls.
iodbc just does not seem to work with Utf-16. This is anecdotical knowledge, though. It might also have been an issue with the data source.
Without this you could not create an ODBC Connection. Status codes in error messages are truncated (less than five letters).
odbc-api
will assume your system has a local using utf-8 encoding. If not expect panics, in case special characters appear in queries or connection strings.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |