Struct oracle::SqlValue

source ·
pub struct SqlValue<'a> { /* private fields */ }
Expand description

A type containing an Oracle value

When this is a column value in a select statement, the Oracle type is determined by the column type.

When this is a bind value in a SQL statement, the Oracle type is determined by ToSql::oratype.

Implementations§

source§

impl SqlValue<'_>

source

pub fn get<T>(&self) -> Result<T>
where T: FromSql,

Gets the Oracle value. It internally does the followings:

  1. Checks whether the conversion from the Oracle type to the target rust type is allowed. It returns Err(Error::InvalidTypeConversion(...)) when it isn’t allowed.
  2. Checks whether the Oracle value is null. When it is null and the return type is Option<FromSql>, it returns Ok(None). When it is null and it isn’t Option<FromSql>, it returns Err(Error::NullValue).
  3. Converts the Oracle value to the rust value. The data type is converted implicitly if required. For example string is converted to i64 by str::parse if get::<i64>() is called for VARCHAR2 columns. If the conversion fails, various errors are returned.
source

pub fn set(&mut self, val: &dyn ToSql) -> Result<()>

Sets a rust value to the Oracle value. It internally does the followings:

  1. Checks whether the conversion from the rust type to the target Oracle type is allowed. It returns Err(Error::InvalidTypeConversion(...)) when it isn’t allowed.
  2. When the argument type is None::<ToSql>, null is set.
  3. Otherwise, converts the rust value to the Oracle value. The data type is converted implicitly if required. For example i64 is converted to string by to_string() if set(100i64) is called for VARCHAR2 columns. When the argument is None::<ToSql> If the conversion fails, various errors are returned.
source

pub fn is_null(&self) -> Result<bool>

Returns Ok(true) when the SQL value is null. Ok(false) when it isn’t null.

source

pub fn set_null(&mut self) -> Result<()>

Sets null to the SQL value.

source

pub fn oracle_type(&self) -> Result<&OracleType>

Gets the Oracle type of the SQL value.

Trait Implementations§

source§

impl Debug for SqlValue<'_>

source§

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

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

impl Display for SqlValue<'_>

source§

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

Formats any SQL value to string using the given formatter. Note that both a null value and a string NULL are formatted as NULL.

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for SqlValue<'a>

§

impl<'a> Send for SqlValue<'a>

§

impl<'a> !Sync for SqlValue<'a>

§

impl<'a> Unpin for SqlValue<'a>

§

impl<'a> !UnwindSafe for SqlValue<'a>

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> 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.