Struct mimerrust::Statement

source ·
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

source

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

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

pub fn bind(&self, value: &dyn ToSql, idx: i16) -> Result<i32, i32>

Binds the value of a parameter in a query. The parameter is identified by its index, starting at 1.

§Examples

See example for execute.

source

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

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

pub fn num_params(&self) -> Result<usize, i32>

Returns the number of parameters in a statement.

source

pub fn get_parameter_mode(&self, idx: i16) -> Result<ParameterMode, i32>

Detects the input/output mode of a parameter.

source

pub fn get_parameter_name(&self, idx: i16) -> Result<String, i32>

Returns the name of a parameter in a statement.

source

pub fn get_column_name(&self, idx: i16) -> Result<String, i32>

Returns the name of a column in a statement.

source

pub fn column_count(&self) -> Result<i32, i32>

Returns the number of columns in a statement.

source

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

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§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

§

fn is_within(&self, b: &G2) -> bool