Struct oracle::sql_type::IntervalYM

source ·
pub struct IntervalYM { /* private fields */ }
Expand description

Oracle-specific Interval Year to Month data type.

§Examples

// Create an interval by new().
let intvl1 = IntervalYM::new(2, 3);

// All arguments must be zero or negative to create a negative interval.
let intvl2 = IntervalYM::new(-2, -3);

// Convert to string.
assert_eq!(intvl1.to_string(), "+000000002-03");
assert_eq!(intvl2.to_string(), "-000000002-03");

// Create an interval with precision.
let intvl3 = IntervalYM::new(2, 3).and_prec(3);

// The string representation depends on the precisions.
assert_eq!(intvl3.to_string(), "+002-03");

// Precisions are ignored when intervals are compared.
assert!(intvl1 == intvl3);

// Create an interval from string.
let intvl4: IntervalYM = "+002-3".parse()?;

// The precision is determined by number of decimal digits in the string.
assert_eq!(intvl4.precision(), 3);

Fetch and bind interval values.

let conn = Connection::connect("scott", "tiger", "")?;

// Fetch IntervalYM
let sql = "select interval '+02-03' year to month from dual";
let intvl = conn.query_row_as::<IntervalYM>(sql, &[])?;
assert_eq!(intvl.to_string(), "+02-03");

// Bind IntervalYM
let sql = "begin \
             :outval := to_timestamp('2017-08-09', 'yyyy-mm-dd') + :inval; \
           end;";
let mut stmt = conn.statement(sql).build()?;
stmt.execute(&[&OracleType::Date, // bind null as date
               &intvl, // bind the intvl variable
              ])?;
let outval: Timestamp = stmt.bind_value(1)?; // get the first bind value.
// 2017-08-09 + (2 years and 3 months)
assert_eq!(outval.to_string(), "2019-11-09 00:00:00");

Implementations§

source§

impl IntervalYM

source

pub fn new(years: i32, months: i32) -> IntervalYM

Creates a new IntervalYM.

Valid values are:

argumentvalid values
years-999999999 to 999999999
months-11 to 11

All arguments must be zero or positive to create a positive interval. All arguments must be zero or negative to create a negative interval.

source

pub fn and_prec(&self, precision: u8) -> IntervalYM

Creates a new IntervalYM with precision.

The precision affects text representation of IntervalYM. It doesn’t affect comparison.

source

pub fn years(&self) -> i32

Returns years component.

source

pub fn months(&self) -> i32

Returns months component.

source

pub fn precision(&self) -> u8

Returns precision.

Trait Implementations§

source§

impl Clone for IntervalYM

source§

fn clone(&self) -> IntervalYM

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for IntervalYM

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for IntervalYM

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl FromSql for IntervalYM

source§

impl FromStr for IntervalYM

§

type Err = ParseOracleTypeError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl PartialEq for IntervalYM

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl ToSql for IntervalYM

source§

fn oratype(&self, _conn: &Connection) -> Result<OracleType>

source§

fn to_sql(&self, val: &mut SqlValue<'_>) -> Result<()>

source§

impl ToSqlNull for IntervalYM

source§

impl Copy for IntervalYM

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> RowValue for T
where T: FromSql,

source§

fn get(row: &Row) -> Result<T, Error>

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.