Struct oracle::Statement
[−]
[src]
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 bind<I>(&mut self, bindidx: I, value: &ToSql) -> Result<()> where
I: BindIndex,
[src]
I: BindIndex,
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", "", &[]).unwrap(); let mut stmt = conn.prepare("begin :outval := upper(:inval); end;").unwrap(); // Sets NULL whose data type is VARCHAR2(60) to the first bind value. stmt.bind(1, &OracleType::Varchar2(60)).unwrap(); // Sets "to be upper-case" to the second by its name. stmt.bind("inval", &"to be upper-case").unwrap(); stmt.execute(&[]).unwrap(); let outval: String = stmt.bind_value(1).unwrap(); assert_eq!(outval, "TO BE UPPER-CASE");
pub fn bind_value<I, T>(&self, bindidx: I) -> Result<T> where
I: BindIndex,
T: FromSql,
[src]
I: BindIndex,
T: FromSql,
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", "", &[]).unwrap(); // 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;").unwrap(); stmt.execute(&[&OracleType::Varchar2(60), &"to be upper-case"]).unwrap(); // Get the first bind value by position. let outval: String = stmt.bind_value(1).unwrap(); assert_eq!(outval, "TO BE UPPER-CASE"); // Get the first bind value by name. let outval: String = stmt.bind_value("outval").unwrap(); assert_eq!(outval, "TO BE UPPER-CASE");
pub fn query(&mut self, params: &[&ToSql]) -> Result<ResultSet<Row>>
[src]
Executes the prepared statement and returns an Iterator over rows.
pub fn query_named(
&mut self,
params: &[(&str, &ToSql)]
) -> Result<ResultSet<Row>>
[src]
&mut self,
params: &[(&str, &ToSql)]
) -> Result<ResultSet<Row>>
Executes the prepared statement and returns an Iterator over rows.
pub fn query_as<'a, T>(
&'a mut self,
params: &[&ToSql]
) -> Result<ResultSet<'a, T>> where
T: RowValue,
[src]
&'a mut self,
params: &[&ToSql]
) -> Result<ResultSet<'a, T>> where
T: RowValue,
Executes the prepared statement and returns an Iterator over rows.
The iterator returns Result<T>
where T is the specified type.
Examples
let conn = Connection::connect("scott", "tiger", "", &[]).unwrap(); let mut stmt = conn.prepare("select ename, sal, comm from emp where deptno = :1").unwrap(); let rows = stmt.query_as::<(String, i32, Option<i32>)>(&[&10]).unwrap(); println!("---------------|---------------|---------------|"); for row_result in rows { let (ename, sal, comm) = row_result.unwrap(); println!(" {:14}| {:>10} | {:>10} |", ename, sal, comm.map_or("".to_string(), |v| v.to_string())); }
pub fn query_as_named<'a, T>(
&'a mut self,
params: &[(&str, &ToSql)]
) -> Result<ResultSet<'a, T>> where
T: RowValue,
[src]
&'a mut self,
params: &[(&str, &ToSql)]
) -> Result<ResultSet<'a, T>> where
T: RowValue,
Executes the prepared statement and returns an Iterator over rows.
The iterator returns Result<T>
where T is the specified type.
Bind parameters are bound by their names.
Examples
let conn = Connection::connect("scott", "tiger", "", &[]).unwrap(); let mut stmt = conn.prepare("select ename, sal, comm from emp where deptno = :deptno").unwrap(); let rows = stmt.query_as_named::<(String, i32, Option<i32>)>(&[("deptno", &10)]).unwrap(); println!("---------------|---------------|---------------|"); for row_result in rows { let (ename, sal, comm) = row_result.unwrap(); println!(" {:14}| {:>10} | {:>10} |", ename, sal, comm.map_or("".to_string(), |v| v.to_string())); }
pub fn query_row(&mut self, params: &[&ToSql]) -> Result<Row>
[src]
Gets the first row from the prepared statement.
If the query returns more than one row, all rows except the first are ignored.
It returns Err(Error::NoDataFound)
when no rows are found.
pub fn query_row_named(&mut self, params: &[(&str, &ToSql)]) -> Result<Row>
[src]
Gets one row from the prepared statement using named bind parameters.
If the query returns more than one row, all rows except the first are ignored.
It returns Err(Error::NoDataFound)
when no rows are found.
pub fn query_row_as<T>(&mut self, params: &[&ToSql]) -> Result<T::Item> where
T: RowValue,
[src]
T: RowValue,
Gets one row from the prepared statement as specified type.
If the query returns more than one row, all rows except the first are ignored.
It returns Err(Error::NoDataFound)
when no rows are found.
pub fn query_row_as_named<T>(
&mut self,
params: &[(&str, &ToSql)]
) -> Result<T::Item> where
T: RowValue,
[src]
&mut self,
params: &[(&str, &ToSql)]
) -> Result<T::Item> where
T: RowValue,
Gets one row from the prepared statement as specified type using named bind parameters.
If the query returns more than one row, all rows except the first are ignored.
It returns Err(Error::NoDataFound)
when no rows are found.
pub fn execute(&mut self, params: &[&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", "", &[]).unwrap(); // execute a statement without bind parameters let mut stmt = conn.prepare("insert into emp(empno, ename) values (113, 'John')").unwrap(); stmt.execute(&[]).unwrap(); // execute a statement with binding parameters by position let mut stmt = conn.prepare("insert into emp(empno, ename) values (:1, :2)").unwrap(); stmt.execute(&[&114, &"Smith"]).unwrap(); stmt.execute(&[&115, &"Paul"]).unwrap(); // execute with other values.
pub fn execute_named(&mut self, params: &[(&str, &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", "", &[]).unwrap(); // execute a statement with binding parameters by name let mut stmt = conn.prepare("insert into emp(empno, ename) values (:id, :name)").unwrap(); stmt.execute_named(&[("id", &114), ("name", &"Smith")]).unwrap(); stmt.execute_named(&[("id", &115), ("name", &"Paul")]).unwrap(); // 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", "", &[]).unwrap(); // SQL statements let stmt = conn.prepare("select :val1, :val2, :val1 from dual").unwrap(); assert_eq!(stmt.bind_count(), 3); // val1, val2 and val1 // PL/SQL statements let stmt = conn.prepare("begin :val1 := :val1 || :val2; end;").unwrap(); 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", "", &[]).unwrap(); let stmt = conn.prepare("BEGIN :val1 := :val2 || :val1 || :aàáâãäå; END;").unwrap(); 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 statement_type(&self) -> StatementType
[src]
Returns statement type
pub fn set_fetch_array_size(&mut self, fetch_array_size: u32)
[src]
Sets the array size used for performing fetches.
This specifies the number of rows allocated before performing fetches. The higher this value is the less network round trips are required to fetch rows from the database but more memory is also required.
pub fn is_returning(&self) -> bool
[src]
Returns true when the SQL statement has a RETURNING INTO
clause.