44 个版本

使用旧的 Rust 2015

0.17.0 2020年5月9日
0.16.1 2019年12月18日
0.16.0 2019年11月27日
0.14.0 2019年7月11日
0.1.0 2016年2月19日

#2611数据库接口

Download history 285/week @ 2023-11-19 254/week @ 2023-11-26 144/week @ 2023-12-03 375/week @ 2023-12-10 233/week @ 2023-12-17 215/week @ 2023-12-24 184/week @ 2023-12-31 170/week @ 2024-01-07 254/week @ 2024-01-14 345/week @ 2024-01-21 477/week @ 2024-01-28 444/week @ 2024-02-04 139/week @ 2024-02-11 253/week @ 2024-02-18 291/week @ 2024-02-25 188/week @ 2024-03-03

882 每月下载量
用于 6 个 Crates (3 直接)

MIT 许可证

90KB
2K SLoC

安全的 Rust ODBC 封装

用于在 Rust 中编写 ODBC 应用的库。

如果您正在寻找原始的 ODBC FFI 封装,请查看 odbc-safeodbc-sys crate。

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

文档也在这里可用 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(())
}

依赖项

~3.5MB
~121K SLoC