44 releases

0.17.0 May 9, 2020
0.16.1 Dec 18, 2019
0.16.0 Nov 27, 2019
0.14.0 Jul 11, 2019
0.1.0 Feb 19, 2016

#12 in Database interfaces

Download history 535/week @ 2020-01-25 663/week @ 2020-02-01 533/week @ 2020-02-08 578/week @ 2020-02-15 765/week @ 2020-02-22 464/week @ 2020-02-29 612/week @ 2020-03-07 555/week @ 2020-03-14 585/week @ 2020-03-21 474/week @ 2020-03-28 290/week @ 2020-04-04 700/week @ 2020-04-11 467/week @ 2020-04-18 359/week @ 2020-04-25 444/week @ 2020-05-02 492/week @ 2020-05-09

2,270 downloads per month
Used in 5 crates (2 directly)

MIT license

89KB
2K SLoC

Ruby HTML 2K SLoC // 0.2% comments Scons 16 SLoC Idris 10 SLoC

ODBC wrapper for safe idiomatic Rust

Library for writing ODBC applications in Rust.

If you're looking for raw ODBC FFI bindings check odbc-safe and odbc-sys crate.

https://travis-ci.org/Koka/odbc-rs Build status https://crates.io/crates/odbc Coverage Status Docs Join the chat at https://gitter.im/odbc-rs/odbc

Docs are also available here

extern crate odbc;
// Use this crate and set environmet variable RUST_LOG=odbc to see ODBC warnings
extern crate env_logger;
use odbc::*;
use std::io;
use odbc_safe::AutocommitOn;

fn main() {

    env_logger::init();

    match connect() {
        Ok(()) => println!("Success"),
        Err(diag) => println!("Error: {}", diag),
    }
}

fn connect() -> std::result::Result<(), DiagnosticRecord> {

    let env = create_environment_v3().map_err(|e| e.unwrap())?;

    let mut buffer = String::new();
    println!("Please enter connection string: ");
    io::stdin().read_line(&mut buffer).unwrap();

    let conn = env.connect_with_connection_string(&buffer)?;
    execute_statement(&conn)
}

fn execute_statement<'env>(conn: &Connection<'env, AutocommitOn>) -> Result<()> {
    let stmt = Statement::with_parent(conn)?;

    let mut sql_text = String::new();
    println!("Please enter SQL statement string: ");
    io::stdin().read_line(&mut sql_text).unwrap();

    match stmt.exec_direct(&sql_text)? {
        Data(mut stmt) => {
            let cols = stmt.num_result_cols()?;
            while let Some(mut cursor) = stmt.fetch()? {
                for i in 1..(cols + 1) {
                    match cursor.get_data::<&str>(i as u16)? {
                        Some(val) => print!(" {}", val),
                        None => print!(" NULL"),
                    }
                }
                println!("");
            }
        }
        NoData(_) => println!("Query executed, no data returned"),
    }

    Ok(())
}

Dependencies

~3.5MB
~128K SLoC