Expand description
ODBC driver for SQLx.
sqlx-odbc connects SQLx to databases exposed through an ODBC driver
manager. Use it directly with sqlx-core native APIs, or install its
Any driver when an application wants to open ODBC connection
strings through AnyConnection.
§Native connection
use sqlx_core::connection::Connection;
use sqlx_core::row::Row;
use sqlx_odbc::OdbcConnection;
let mut conn = OdbcConnection::connect("Driver=DuckDB;Database=/tmp/example.duckdb").await?;
let row = sqlx_core::query::query("SELECT 1")
.fetch_one(&mut conn)
.await?;
let value: i32 = row.try_get(0)?;
assert_eq!(value, 1);
conn.close().await?;OdbcConnection::connect() accepts a standard ODBC connection string, a bare
DSN name, or the legacy odbc: prefix.
§AnyConnection
Install this driver before connecting through SQLx Any APIs:
use sqlx_core::connection::Connection;
sqlx_core::any::driver::install_drivers(&[sqlx_odbc::any::DRIVER])?;
let mut conn = sqlx_core::any::AnyConnection::connect(
"odbc:Driver=DuckDB;Database=/tmp/example.duckdb",
)
.await?;
conn.close().await?;To combine split drivers, install all of them once at application startup:
fn install() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
sqlx_core::any::driver::install_drivers(&[
sqlx_sqlserver::any::DRIVER,
sqlx_odbc::any::DRIVER,
])?;
Ok(())
}§Native ODBC requirements
On Linux and macOS, install a driver manager such as unixODBC plus a
database-specific ODBC driver. On Windows, the driver manager is built in,
but the database-specific driver is still required. DSNs can be configured in
the driver manager, or callers can pass a full Driver=...;... connection
string.
Enable the vendored-unix-odbc feature to statically link the unixODBC
driver manager into your application on Linux or macOS. The actual database
ODBC driver still needs to be installed and discoverable at runtime.
Buffered fetching can improve throughput, but long text or binary values may
be truncated when max_column_size is set. Use unbuffered mode for values
that may exceed that limit.
Modules§
- any
- Runtime
Anydriver support for ODBC.
Structs§
- Odbc
- ODBC database marker for SQLx-core traits.
- Odbc
Arguments - Argument buffer for ODBC queries.
- Odbc
Buffer Settings - Fetch-buffer settings used by the ODBC driver.
- Odbc
Column - Column metadata for an ODBC row or statement.
- Odbc
Connect Options - Connection options for an ODBC data source.
- Odbc
Connection - Blocking ODBC connection wrapper.
- Odbc
Database Error - Database error details extracted from ODBC diagnostics.
- Odbc
Parameter Collection - Owned ODBC parameter storage ready to bind with
odbc-api. - Odbc
Query Result - Result summary for an ODBC query.
- OdbcRow
- Minimal ODBC row container used by the SQLx-core skeleton.
- Odbc
Statement - Prepared statement metadata for ODBC.
- Odbc
Transaction Manager - Transaction manager placeholder for ODBC.
- Odbc
Type Info - Type information for an ODBC value.
- Odbc
Value - A small owned ODBC value representation used by unit tests and Any-mapping work.
Enums§
- Odbc
Argument Value - Values that can currently be bound to ODBC parameters.
- Odbc
Error - Error type returned by this crate while the SQLx driver port is in progress.
- Odbc
Value Kind - Supported owned ODBC value kinds.
Traits§
- Data
Type Ext - Helper predicates for
odbc-apidata type groups. - Odbc
Executor - An alias for
Executor<'_, Database = Odbc>.
Type Aliases§
- Odbc
Pool - An alias for
Pool, specialized for ODBC. - Odbc
Pool Options - An alias for
PoolOptions, specialized for ODBC. - Odbc
Transaction - An alias for
Transaction, specialized for ODBC. - Result
- Result alias for this crate.