Struct oracle::Statement [] [src]

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

Statement

Methods

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

[src]

Closes the statement before the end of lifetime.

[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", "", &[]).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");

[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", "", &[]).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");

[src]

Executes the prepared statement and returns an Iterator over rows.

[src]

Executes the prepared statement and returns an Iterator over rows.

[src]

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()));
}

[src]

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()));
}

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

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

[src]

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.

[src]

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.

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

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

[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

[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ÀÁÂÃÄÅ");

[src]

Returns statement type

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

[src]

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

Trait Implementations

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

[src]

Executes the destructor for this type. Read more

Auto Trait Implementations

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

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