Rust-oracle

This is an Oracle database driver for Rust based on ODPI-C.

Don't use this until the version number reaches to 0.1.0.

Methods for querying rows were changed in 0.0.4. If you had written programs using rust-oracle before 0.0.4, enable the restore-deleted feature in Cargo.toml. It restores deleted methods and disables statement-type checking in execute methods.

Build-time Requirements

Run-time Requirements

Usage

text [dependencies] oracle = "0.0.4"

When you need to fetch or bind chrono data types, enable chrono feature:

text [dependencies] oracle = { version = "0.0.4", features = ["chrono"] }

If you had written programs using rust-oracle before 0.0.4, enable the restore-deleted feature. It restores deleted methods and disables statement-type checking in execute methods.

text [dependencies] oracle = { version = "0.0.4", features = ["restore-deleted"] }

Examples

Select a table:

```rust extern crate oracle;

fn main() { // Connect to a database. let conn = oracle::Connection::new("scott", "tiger", "//localhost/XE").unwrap(); // Select a table with a bind variable. let mut stmt = conn.prepare("select ename, sal, comm from emp where deptno = :1").unwrap(); let rows = stmt.query(&[&30]).unwrap();

// Print column names
for info in rows.column_info() {
    print!(" {:14}|", info.name());
}
println!("");

// Print column types
for info in rows.column_info() {
    print!(" {:14}|", info.oracle_type().to_string());
}
println!("");

// Print column values
println!("---------------|---------------|---------------|");
for row_result in rows {
    let row = row_result.unwrap();
    // get a column value by position (0-based)
    let ename: String = row.get(0).unwrap();
    // get a column by name (case-insensitive)
    let sal: i32 = row.get("sal").unwrap();
    // get a nullable column
    let comm: Option<i32> = row.get(2).unwrap();

    println!(" {:14}| {:>10}    | {:>10}    |",
             ename,
             sal,
             comm.map_or("".to_string(), |v| v.to_string()));
}

} ```

NLS_LANG parameter

NLS_LANG consists of three components: language, territory and charset. However the charset component is ignored and UTF-8(AL32UTF8) is used as charset because rust characters are UTF-8.

The territory component specifies numeric format, date format and so on. However it affects only conversion in Oracle. See the following example:

```rust // The territory is France. std::env::setvar("NLSLANG", "french_france.AL32UTF8"); let conn = oracle::Connection::new("scott", "tiger", "").unwrap();

// 10.1 is converted to a string in Oracle and fetched as a string. let result = conn.queryrowas::("select tochar(10.1) from dual", &[]).unwrap(); asserteq!(result, "10,1"); // The decimal mark depends on the territory.

// 10.1 is fetched as a number and converted to a string in rust-oracle let result = conn.queryrowas::("select 10.1 from dual", &[]).unwrap(); assert_eq!(result, "10.1"); // The decimal mark is always period(.). ```

Note that NLS_LANG must be set before first rust-oracle function execution if required.

TODO

License

Rust-oracle itself is under 2-clause BSD-style license.

ODPI-C bundled in rust-oracle is under the terms of:

  1. the Universal Permissive License v 1.0 or at your option, any later version; and/or
  2. the Apache License v 2.0.