MCPcopy Index your code
hub / github.com/Koka/odbc-rs

github.com/Koka/odbc-rs @0.17.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.17.0 ↗ · + Follow
186 symbols 521 edges 26 files 51 documented · 27%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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(())
}

Extension points exported contracts — how you extend this code

Handle (Interface)
Reflects the ability of a type to expose a valid handle [8 implementers]
src/lib.rs
OdbcType (Interface)
(no doc) [25 implementers]
src/statement/types.rs
OdbcObject (Interface)
Trait to be implemented by all opaque types which are referenced by handles in the ffi layer [3 implementers]
src/odbc_object.rs
GetDiagRec (Interface)
Allows retrieving a diagnostic record, describing errors (or lack thereof) during the last operation. [1 implementers]
src/diagnostics.rs
Extract (Interface)
(no doc) [1 implementers]
examples/custom_get_data.rs
Output (Interface)
Indicates that a type can be retrieved using `Cursor::get_data` [1 implementers]
src/statement/output.rs
MySupportedType (Interface)
(no doc) [1 implementers]
examples/custom_get_data.rs

Core symbols most depended-on inside this repo

create_environment_v3
called by 29
src/environment/mod.rs
connect
called by 21
src/connection.rs
into_result
called by 21
src/result.rs
fetch
called by 20
src/statement/mod.rs
exec_direct
called by 18
src/statement/mod.rs
get_diag_rec
called by 14
src/diagnostics.rs
handle
called by 14
src/statement/mod.rs
bind_parameter
called by 14
src/statement/input.rs

Shape

Function 80
Method 80
Class 13
Interface 7
Enum 6

Languages

Rust100%

Modules by API surface

src/statement/mod.rs26 symbols
tests/libs.rs17 symbols
tests/native_types.rs15 symbols
tests/input_parameter.rs15 symbols
src/statement/types.rs15 symbols
tests/gbk.rs13 symbols
src/diagnostics.rs12 symbols
src/environment/list_data_sources.rs11 symbols
src/connection.rs10 symbols
src/statement/prepare.rs6 symbols
src/environment/mod.rs6 symbols
examples/custom_get_data.rs6 symbols

For agents

$ claude mcp add odbc-rs \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page