pub struct Statement { /* private fields */ }Expand description
A prepared statement.
Each prepared statement is created through prepare, and can only be executed on the connection that created it.
Implementations§
source§impl Statement
impl Statement
sourcepub fn execute(&self) -> Result<i32, i32>
pub fn execute(&self) -> Result<i32, i32>
Executes this statement. Equivalent to calling execute_bind with an empty set of parameters, i.e “stmnt.execute_bind(&[]);”.
§Errors
Returns Err when the statement couldn’t be executed, e.g. if the statment has unset named parameters.
§Examples
let mut conn = Connection::open(db, ident, pass).unwrap();
let stmnt = conn.prepare("INSERT INTO test_table VALUES(:string,:int)", CursorMode::Forward).unwrap();
let s = String::from("the number one");
let i = 1;
stmnt.bind(&s,1).unwrap();
stmnt.bind(&i,2).unwrap();
stmnt.execute().unwrap();sourcepub fn execute_bind(&self, params: &[&dyn ToSql]) -> Result<i32, i32>
pub fn execute_bind(&self, params: &[&dyn ToSql]) -> Result<i32, i32>
Executes a statement. If the statement query contains named parameters, the parameter values are expected to be given in order in the “params” argument to this method. If the statement query does not contain named parameters or if the parameters have already been set, the “params” argument is expected to be empty. Parameter values can also be set using the bind method. Alternatively see execute, which does not set parameters prior to executing.
§Errors
Returns Err when the statement couldn’t be executed, e.g. if the database server is stopped or if a parameter could not be set.
§Examples
let mut conn = Connection::open(db, ident, pass).unwrap();
let stmnt = conn.prepare("INSERT INTO test_table VALUES(:string,:int)", CursorMode::Forward).unwrap();
let s = String::from("the number one");
let i = 1;
stmnt.execute_bind(&[&s,&i]).unwrap();sourcepub fn open_cursor(&self) -> Result<Cursor, i32>
pub fn open_cursor(&self) -> Result<Cursor, i32>
Opens a Cursor for a statement.
The CursorMode of the cursor (Forward or Scrollable) is specified when the statement is created in Prepare.
§Errors
Returns Err when a cursor couldn’t be opened.
§Examples
let mut conn = Connection::open(db, ident, pass).unwrap();
let stmnt = conn.prepare("SELECT * FROM test_table", CursorMode::Forward).unwrap();
let mut cursor = stmnt.open_cursor().unwrap();sourcepub fn get_error(&self, error_code: i32) -> MimerError
pub fn get_error(&self, error_code: i32) -> MimerError
Returns a MimerError given a Statement and a return code. This can be errors from the Mimer database itself, or errors from the Mimer Rust API.
§Errors
Returns Err when this method fails. It will still return a MimerError explaining what failed in this method.
§Examples
let mut conn = Connection::open(db, ident, pass).unwrap();
let stmnt = conn.prepare("INSERT INTO test_table VALUES('the number one',1)", CursorMode::Forward).unwrap();
let err = match stmnt.get_column_name(1) {
Ok(_) => panic!("Function worked when it shouldn't have!"),
Err(ec) => stmnt.get_error(ec),
};
println!("{}",err);sourcepub fn num_params(&self) -> Result<usize, i32>
pub fn num_params(&self) -> Result<usize, i32>
Returns the number of parameters in a statement.
sourcepub fn get_parameter_mode(&self, idx: i16) -> Result<ParameterMode, i32>
pub fn get_parameter_mode(&self, idx: i16) -> Result<ParameterMode, i32>
Detects the input/output mode of a parameter.
sourcepub fn get_parameter_name(&self, idx: i16) -> Result<String, i32>
pub fn get_parameter_name(&self, idx: i16) -> Result<String, i32>
Returns the name of a parameter in a statement.
sourcepub fn get_column_name(&self, idx: i16) -> Result<String, i32>
pub fn get_column_name(&self, idx: i16) -> Result<String, i32>
Returns the name of a column in a statement.
sourcepub fn column_count(&self) -> Result<i32, i32>
pub fn column_count(&self) -> Result<i32, i32>
Returns the number of columns in a statement.
sourcepub fn set_array_size(&self, size: i32) -> Result<i32, i32>
pub fn set_array_size(&self, size: i32) -> Result<i32, i32>
Sets the array size when fetching data from a statement. By default the Mimer API routines MimerFetch and MimerFetchSkip uses an internal fetch buffer equal to the maximum size of one row. Depending on the actual size of the data, this buffer may hold more than one row. By increasing the array size, more data is retrieved in each server request.
§Parameters
size: The number of rows to retrieve in each request.
sourcepub fn add_batch(&mut self, params: &[&dyn ToSql]) -> Result<i32, i32>
pub fn add_batch(&mut self, params: &[&dyn ToSql]) -> Result<i32, i32>
Set parameters to a prepared statement, and add it to the batch of statments to be executed on the next call to execute. Note that the statement needs to be declared as mut.
If the statement query contains named parameters, the parameter values are expected to be given in order in the “params” argument to this method. If the statement query does not contain named parameters, the “params” argument is expected to be empty. Can not be used with statements which return result sets, e.g. “SELECT” statements.
§Errors
Returns Err when the parameters could not be set or if the statement handle was invalid.
§Examples
let mut conn = Connection::open(db, ident, pass).unwrap();
let mut stmnt = conn.prepare("INSERT INTO test_table VALUES(:string,:int)", CursorMode::Forward).unwrap();
let s1 = String::from("hello");
let i1 = 1;
let s2 = String::from("world");
let i2 = 2;
stmnt.add_batch(&[&s1,&i1]).unwrap();
stmnt.add_batch(&[&s2,&i2]).unwrap();
stmnt.execute().unwrap();Auto Trait Implementations§
impl Freeze for Statement
impl !RefUnwindSafe for Statement
impl Send for Statement
impl Sync for Statement
impl Unpin for Statement
impl !UnwindSafe for Statement
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more