Giter Club home page Giter Club logo

rust-oracle's Introduction

Rust-oracle - Work in progress

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.

Build-time Requirements

  • Rust 1.18 or later
  • C compiler. See Compile-time Requirements in this document.

Run-time Requirements

Usage

Rust-oracle was published to crates.io. However it is old. Use rust-oracle in the github.

[dependencies]
oracle = { git = "https://github.com/kubo/rust-oracle.git" }

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

[dependencies]
oracle = { git = "https://github.com/kubo/rust-oracle.git", features = ["chrono"] }

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:

// The territory is France.
std::env::set_var("NLS_LANG", "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 mut stmt = conn.execute("select to_char(10.1) from dual", &[]).unwrap();
let row = stmt.fetch().unwrap();
let result: String = row.get(0).unwrap();
assert_eq!(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 mut stmt = conn.execute("select 10.1 from dual", &[]).unwrap();
let row = stmt.fetch().unwrap();
let result: String = row.get(0).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.

Conversion from Oracle types to Rust types

Values in Oracle are converted to Rust type as possible as it can. The following table indicates supported conversion.

Oracle Type Rust Type
CHAR, NCHAR, VARCHAR2, NVARCHAR2 String
โ€ณ i8, i16, i32, i64, u8, u16, u32, u64 via parse()
... ...

This conversion is used also to get values from output parameters.

Conversion from Rust types to Oracle types

When a rust value is set to an input parameter, its Oracle type is determined by the rust type.

Rust Type Oracle Type
str, String NVARCHAR2(length of the rust value)
i8, i16, i32, i64, u8, u16, u32, u64, f32, f64 NUMBER
Vec<u8> RAW(length of the rust value)
oracle::Timestamp TIMESTAMP(9) WITH TIME ZONE
oracle::IntervalDS INTERVAL DAY(9) TO SECOND(9)
oracle::IntervalYM INTERVAL YEAR(9) TO MONTH

When chrono feature is enabled, the following conversions are added.

Rust Type Oracle Type
chrono::Date TIMESTAMP(0) WITH TIME ZONE
chrono::DateTime TIMESTAMP(9) WITH TIME ZONE
chrono::naive::NaiveDate TIMESTAMP(0)
chrono::naive::NaiveDateTime TIMESTAMP(9)
chrono::Duration INTERVAL DAY(9) TO SECOND(9)

TODO

  • Connection pooling
  • Read and write LOB as stream
  • REF CURSOR, BOOLEAN
  • Autocommit mode
  • Scrollable cursors

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.