[][src]Struct oracle::Statement

pub struct Statement<'conn> { /* fields omitted */ }

Statement

Methods

impl<'conn> Statement<'conn>[src]

pub fn close(&mut self) -> Result<()>[src]

Closes the statement before the end of lifetime.

pub fn query(&mut self, params: &[&dyn ToSql]) -> Result<ResultSet<Row>>[src]

Executes the prepared statement and returns a result set containing Rows.

See Query Methods.

pub fn query_named(
    &mut self,
    params: &[(&str, &dyn ToSql)]
) -> Result<ResultSet<Row>>
[src]

Executes the prepared statement using named parameters and returns a result set containing Rows.

See Query Methods.

pub fn query_as<'a, T>(
    &'a mut self,
    params: &[&dyn ToSql]
) -> Result<ResultSet<'a, T>> where
    T: RowValue
[src]

Executes the prepared statement and returns a result set containing RowValues.

See Query Methods.

pub fn query_as_named<'a, T>(
    &'a mut self,
    params: &[(&str, &dyn ToSql)]
) -> Result<ResultSet<'a, T>> where
    T: RowValue
[src]

Executes the prepared statement using named parameters and returns a result set containing RowValues.

See Query Methods.

pub fn query_row(&mut self, params: &[&dyn ToSql]) -> Result<Row>[src]

Gets one row from the prepared statement using positoinal bind parameters.

See Query Methods.

pub fn query_row_named(&mut self, params: &[(&str, &dyn ToSql)]) -> Result<Row>[src]

Gets one row from the prepared statement using named bind parameters.

See Query Methods.

pub fn query_row_as<T>(&mut self, params: &[&dyn ToSql]) -> Result<T> where
    T: RowValue
[src]

Gets one row from the prepared statement as specified type using positoinal bind parameters.

See Query Methods.

pub fn query_row_as_named<T>(
    &mut self,
    params: &[(&str, &dyn ToSql)]
) -> Result<T> where
    T: RowValue
[src]

Gets one row from the prepared statement as specified type using named bind parameters.

See Query Methods.

pub fn execute(&mut self, params: &[&dyn ToSql]) -> Result<()>[src]

Binds values by position and executes the statement. It will retunrs Err when the statemnet is a select statement.

See also Connection.execute.

Examples

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

// execute a statement without bind parameters
let mut stmt = conn.prepare("insert into emp(empno, ename) values (113, 'John')", &[])?;
stmt.execute(&[])?;

// execute a statement with binding parameters by position
let mut stmt = conn.prepare("insert into emp(empno, ename) values (:1, :2)", &[])?;
stmt.execute(&[&114, &"Smith"])?;
stmt.execute(&[&115, &"Paul"])?;  // execute with other values.

pub fn execute_named(&mut self, params: &[(&str, &dyn ToSql)]) -> Result<()>[src]

Binds values by name and executes the statement. It will retunrs Err when the statemnet is a select statement.

See also Connection.execute_named.

Examples

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

// execute a statement with binding parameters by name
let mut stmt = conn.prepare("insert into emp(empno, ename) values (:id, :name)", &[])?;
stmt.execute_named(&[("id", &114),
                     ("name", &"Smith")])?;
stmt.execute_named(&[("id", &115),
                     ("name", &"Paul")])?; // execute with other values.

pub fn bind_count(&self) -> usize[src]

Returns the number of bind variables in the statement.

In SQL statements this is the total number of bind variables whereas in PL/SQL statements this is the count of the unique bind variables.

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

// SQL statements
let stmt = conn.prepare("select :val1, :val2, :val1 from dual", &[])?;
assert_eq!(stmt.bind_count(), 3); // val1, val2 and val1

// PL/SQL statements
let stmt = conn.prepare("begin :val1 := :val1 || :val2; end;", &[])?;
assert_eq!(stmt.bind_count(), 2); // val1(twice) and val2

pub fn bind_names(&self) -> Vec<&str>[src]

Returns the names of the unique bind variables in the statement.

The bind variable names in statements are converted to upper-case.

Examples

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

let stmt = conn.prepare("BEGIN :val1 := :val2 || :val1 || :aàáâãäå; END;", &[])?;
assert_eq!(stmt.bind_count(), 3);
let bind_names = stmt.bind_names();
assert_eq!(bind_names.len(), 3);
assert_eq!(bind_names[0], "VAL1");
assert_eq!(bind_names[1], "VAL2");
assert_eq!(bind_names[2], "AÀÁÂÃÄÅ");

pub fn bind<I>(&mut self, bindidx: I, value: &dyn ToSql) -> Result<()> where
    I: BindIndex
[src]

Set a bind value in the statement.

The position starts from one when the bind index type is usize. The variable name is compared case-insensitively when the bind index type is &str.

Examples

let conn = Connection::connect("scott", "tiger", "")?;
let mut stmt = conn.prepare("begin :outval := upper(:inval); end;", &[])?;

// Sets NULL whose data type is VARCHAR2(60) to the first bind value.
stmt.bind(1, &OracleType::Varchar2(60))?;

// Sets "to be upper-case" to the second by its name.
stmt.bind("inval", &"to be upper-case")?;

stmt.execute(&[])?;
let outval: String = stmt.bind_value(1)?;
assert_eq!(outval, "TO BE UPPER-CASE");

pub fn bind_value<I, T>(&self, bindidx: I) -> Result<T> where
    I: BindIndex,
    T: FromSql
[src]

Gets a bind value in the statement.

The position starts from one when the bind index type is usize. The variable name is compared case-insensitively when the bind index type is &str.

Examples

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

// Prepares "begin :outval := upper(:inval); end;",
// sets NULL whose data type is VARCHAR2(60) to the first bind variable,
// sets "to be upper-case" to the second and then executes it.
let mut stmt = conn.prepare("begin :outval := upper(:inval); end;", &[])?;
stmt.execute(&[&OracleType::Varchar2(60),
             &"to be upper-case"])?;

// Get the first bind value by position.
let outval: String = stmt.bind_value(1)?;
assert_eq!(outval, "TO BE UPPER-CASE");

// Get the first bind value by name.
let outval: String = stmt.bind_value("outval")?;
assert_eq!(outval, "TO BE UPPER-CASE");

pub fn returned_values<I, T>(&self, bindidx: I) -> Result<Vec<T>> where
    I: BindIndex,
    T: FromSql
[src]

Gets values returned by RETURNING INTO clause.

When the bindidx ponints to a bind variable out of RETURNING INTO clause, the behavior is undefined.

Examples

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

// create a table using identity column (Oracle 12c feature).
conn.execute("create table people (id number generated as identity, name varchar2(30))", &[])?;

// insert one person and return the generated id into :id.
let stmt = conn.execute("insert into people(name) values ('Asimov') returning id into :id", &[&None::<i32>])?;
let inserted_id: i32 = stmt.returned_values("id")?[0];
println!("Asimov's ID is {}", inserted_id);

// insert another person and return the generated id into :id.
let stmt = conn.execute("insert into people(name) values ('Clark') returning id into :id", &[&None::<i32>])?;
let inserted_id: i32 = stmt.returned_values("id")?[0];
println!("Clark's ID is {}", inserted_id);

// delete all people and return deleted names into :name.
let stmt = conn.execute("delete from people returning name into :name", &[&OracleType::Varchar2(30)])?;
let deleted_names: Vec<String> = stmt.returned_values("name")?;
for name in deleted_names {
    println!("{} is deleted.", name);
}

// cleanup
conn.execute("drop table people purge", &[])?;

pub fn row_count(&self) -> Result<u64>[src]

Returns the number of rows fetched when the SQL statement is a query. Otherwise, the number of rows affected.

pub fn statement_type(&self) -> StatementType[src]

Returns statement type

pub fn is_query(&self) -> bool[src]

Returns true when the SQL statement is a query.

pub fn is_plsql(&self) -> bool[src]

Returns true when the SQL statement is a PL/SQL block.

pub fn is_ddl(&self) -> bool[src]

Returns true when the SQL statement is DDL (data definition language).

pub fn is_dml(&self) -> bool[src]

Returns true when the SQL statement is DML (data manipulation language).

pub fn is_returning(&self) -> bool[src]

Returns true when the SQL statement has a RETURNING INTO clause.

Trait Implementations

impl<'conn> Drop for Statement<'conn>[src]

impl<'conn> Debug for Statement<'conn>[src]

Auto Trait Implementations

impl<'conn> !Send for Statement<'conn>

impl<'conn> Unpin for Statement<'conn>

impl<'conn> !Sync for Statement<'conn>

impl<'conn> !UnwindSafe for Statement<'conn>

impl<'conn> !RefUnwindSafe for Statement<'conn>

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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