Skip to main content

Crate sqlx_odbc

Crate sqlx_odbc 

Source
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 Any driver support for ODBC.

Structs§

Odbc
ODBC database marker for SQLx-core traits.
OdbcArguments
Argument buffer for ODBC queries.
OdbcBufferSettings
Fetch-buffer settings used by the ODBC driver.
OdbcColumn
Column metadata for an ODBC row or statement.
OdbcConnectOptions
Connection options for an ODBC data source.
OdbcConnection
Blocking ODBC connection wrapper.
OdbcDatabaseError
Database error details extracted from ODBC diagnostics.
OdbcParameterCollection
Owned ODBC parameter storage ready to bind with odbc-api.
OdbcQueryResult
Result summary for an ODBC query.
OdbcRow
Minimal ODBC row container used by the SQLx-core skeleton.
OdbcStatement
Prepared statement metadata for ODBC.
OdbcTransactionManager
Transaction manager placeholder for ODBC.
OdbcTypeInfo
Type information for an ODBC value.
OdbcValue
A small owned ODBC value representation used by unit tests and Any-mapping work.

Enums§

OdbcArgumentValue
Values that can currently be bound to ODBC parameters.
OdbcError
Error type returned by this crate while the SQLx driver port is in progress.
OdbcValueKind
Supported owned ODBC value kinds.

Traits§

DataTypeExt
Helper predicates for odbc-api data type groups.
OdbcExecutor
An alias for Executor<'_, Database = Odbc>.

Type Aliases§

OdbcPool
An alias for Pool, specialized for ODBC.
OdbcPoolOptions
An alias for PoolOptions, specialized for ODBC.
OdbcTransaction
An alias for Transaction, specialized for ODBC.
Result
Result alias for this crate.