#odbc #database #sql

odbc-api

Write ODBC Applications in (mostly) safe Rust

74 releases (32 breaking)

Uses new Rust 2021

new 0.33.2 Jan 20, 2022
0.32.0 Dec 18, 2021
0.31.1 Nov 28, 2021
0.24.1 Jul 19, 2021
0.10.3 Nov 21, 2020

#19 in Database interfaces

Download history 176/week @ 2021-10-01 289/week @ 2021-10-08 695/week @ 2021-10-15 506/week @ 2021-10-22 417/week @ 2021-10-29 599/week @ 2021-11-05 477/week @ 2021-11-12 717/week @ 2021-11-19 447/week @ 2021-11-26 903/week @ 2021-12-03 472/week @ 2021-12-10 394/week @ 2021-12-17 419/week @ 2021-12-24 703/week @ 2021-12-31 1121/week @ 2022-01-07 818/week @ 2022-01-14

3,161 downloads per month
Used in 4 crates

MIT license

400KB
5.5K SLoC

ODBC-API

Docs Licence Crates.io Coverage Status

Rust ODBC bindings. ODBC (Open Database Connectivity) is an open standard to connect to a variaty of data sources. Most data sources offer ODBC drivers. This crate is currently tested against:

  • Microsoft SQL Server
  • MariaDB
  • SQLite

Current ODBC Version is 3.80.

This crate is build on top of the odbc-sys ffi bindings, which provide definitions of the ODBC C Interface, but do not build any kind of abstraction on top of it.

Usage

Check the guide for code examples and a tour of the features.

Installation

To build this library you need to link against the odbc library of your systems ODBC driver manager. It should be automatically detected by the build. On Windows systems it is preinstalled. On Linux and OS-X unix-odbc must be installed. To create a Connections to a data source, its ODBC driver must also be installed.

Windows

Nothing to do. ODBC driver manager is preinstalled.

Ubuntu

sudo apt-get install unixodbc-dev

OS-X (intel)

You can use homebrew to install UnixODBC

brew install unixodbc

OS-X (ARM / MAC M1)

cargo build is not going to pick up libodbc.so installed via homebrew due to the fact that homebrew on ARM Mac installs into /opt/homebrew/Cellar as opposed to /usr/local/opt/.

You find documentation on what directories are searched during build here: https://doc.rust-lang.org/cargo/reference/environment-variables.html#dynamic-library-paths.

You can also install unixODBC from source:

  1. copy the unixODBC-2.3.9.tar.gz file somewhere you can create files and directories
  2. gunzip unixODBC*.tar.gz
  3. tar xvf unixODBC*.tar
  4. ./configure
  5. make
  6. make install

Features

  • Connect using either Data Source names (DSN)
  • Connect using connection strings
  • Connect using prompts (windows)
  • Support for logging ODBC diagnostics and warnings (via log crate).
  • Support for columnar bulk inserts.
  • Support for columnar bulk queries.
  • Support for rowise bulk inserts.
  • Support for rowise bulk queries.
  • Support for Output parameters of stored procedures.
  • Support prepared and 'one shot' queries.
  • Transactions
  • Pass parameters to queries
  • Support for async
  • Support for Multithreading
  • Support for inserting large binary / text data in stream
  • Support for fetching arbitrary large text / binary data in stream
  • Support for connection pooling
  • List tables of data sources

Dependencies

~1–3.5MB
~74K SLoC