Struct oracle::Statement[][src]

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

Statement

Methods

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

Closes the statement before the end of lifetime.

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

See Query Methods.

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

See Query Methods.

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

See Query Methods.

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

See Query Methods.

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

See Query Methods.

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

See Query Methods.

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

See Query Methods.

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

See Query Methods.

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.

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.

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

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

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");

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");

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

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

Returns statement type

Returns true when the SQL statement is a query.

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

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

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

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

Trait Implementations

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

Executes the destructor for this type. Read more

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

Formats the value using the given formatter. Read more

Auto Trait Implementations

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

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