Struct ibm_db::Statement [−][src]
A Statement
can be used to execute queries and retrieves results.
Implementations
impl<'a, 'b, S, R, AC: AutocommitMode> Statement<'a, 'b, S, R, AC>
[src]
pub fn bind_parameter<'c, T>(
self,
parameter_index: u16,
value: &'c T
) -> Result<Statement<'a, 'c, S, R, AC>, Box<dyn Error>> where
T: OdbcType<'c>,
T: ?Sized,
'b: 'c,
[src]
self,
parameter_index: u16,
value: &'c T
) -> Result<Statement<'a, 'c, S, R, AC>, Box<dyn Error>> where
T: OdbcType<'c>,
T: ?Sized,
'b: 'c,
Binds a parameter to a parameter marker in an SQL statement.
Result
This method will destroy the statement and create a new one which may not outlive the bound parameter. This is to ensure that the statement will not dereference an invalid pointer during execution.
Arguments
parameter_index
- Index of the marker to bind to the parameter. Starting at1
value
- Reference to bind to the marker
Example
let conn = env.connect("TestDataSource", "", "")?; let stmt = Statement::with_parent(&conn)?; let param = 1968; let stmt = stmt.bind_parameter(1, ¶m)?; let sql_text = "SELECT TITLE FROM MOVIES WHERE YEAR = ?"; if let Data(mut stmt) = stmt.exec_direct(sql_text)? { // ... }
pub fn reset_parameters(
self
) -> Result<Statement<'a, 'a, S, R, AC>, Box<dyn Error>>
[src]
self
) -> Result<Statement<'a, 'a, S, R, AC>, Box<dyn Error>>
Releasing all parameter buffers set by bind_parameter
. This method consumes the statement
and returns a new one those lifetime is no longer limited by the buffers bound.
impl<'a, 'b, AC: AutocommitMode> Statement<'a, 'b, Allocated, NoResult, AC>
[src]
pub fn prepare(
self,
sql_text: &str
) -> Result<Statement<'a, 'b, Prepared, NoResult, AC>, Box<dyn Error>>
[src]
self,
sql_text: &str
) -> Result<Statement<'a, 'b, Prepared, NoResult, AC>, Box<dyn Error>>
Prepares a statement for execution. Executing a prepared statement is faster than directly executing an unprepared statement, since it is already compiled into an Access Plan. This makes preparing statement a good idea if you want to repeatedly execute a query with a different set of parameters and care about performance.
Example
let conn = env.connect("TestDataSource", "", "")?; let stmt = Statement::with_parent(&conn)?; let mut stmt = stmt.prepare("SELECT TITLE FROM MOVIES WHERE YEAR = ?")?; fn print_one_movie_from<'a> (year: u16, stmt: Statement<'a,'a, Prepared, NoResult, safe::AutocommitOn>) -> Result<Statement<'a, 'a, Prepared, NoResult, safe::AutocommitOn>>{ let stmt = stmt.bind_parameter(1, &year)?; let stmt = if let Data(mut stmt) = stmt.execute()?{ if let Some(mut cursor) = stmt.fetch()?{ println!("{}", cursor.get_data::<String>(1)?.unwrap()); } stmt.close_cursor()? } else { panic!("SELECT statement returned no result set"); }; stmt.reset_parameters() }; for year in 1990..2010{ stmt = print_one_movie_from(year, stmt)? }
pub fn prepare_bytes(
self,
bytes: &[u8]
) -> Result<Statement<'a, 'b, Prepared, NoResult, AC>, Box<dyn Error>>
[src]
self,
bytes: &[u8]
) -> Result<Statement<'a, 'b, Prepared, NoResult, AC>, Box<dyn Error>>
Prepares a statement for execution. Executing a prepared statement is faster than directly executing an unprepared statement, since it is already compiled into an Access Plan. This makes preparing statement a good idea if you want to repeatedly execute a query with a different set of parameters and care about performance.
Example
let env = create_environment_v3().map_err(|e| e.unwrap())?; let conn = env.connect("TestDataSource", "", "")?; let stmt = Statement::with_parent(&conn)?; // need encode_rs crate // let mut stmt = stmt.prepare_bytes(&GB2312.encode("select '你好' as hello").0)?;
impl<'a, 'b, AC: AutocommitMode> Statement<'a, 'b, Prepared, NoResult, AC>
[src]
pub fn num_result_cols(&self) -> Result<i16, Box<dyn Error>>
[src]
The number of columns in a result set
Can be called successfully only when the statement is in the prepared, executed, or positioned state. If the statement does not return columns the result will be 0.
pub fn describe_col(&self, idx: u16) -> Result<ColumnDescriptor>
[src]
Returns description struct for result set column with a given index. Note: indexing is starting from 1.
pub fn execute(
self
) -> Result<ResultSetState<'a, 'b, Prepared, AC>, Box<dyn Error>>
[src]
self
) -> Result<ResultSetState<'a, 'b, Prepared, AC>, Box<dyn Error>>
Executes a prepared statement.
impl<'a, 'b, 'env, AC: AutocommitMode> Statement<'a, 'b, Allocated, NoResult, AC>
[src]
pub fn with_parent(ds: &'a Connection<'env, AC>) -> Result<Self, Box<dyn Error>>
[src]
pub fn affected_row_count(&self) -> Result<i64>
[src]
pub fn tables(
self,
catalog_name: &String,
schema_name: &String,
table_name: &String,
table_type: &String
) -> Result<Statement<'a, 'b, Executed, HasResult, AC>, Box<dyn Error>>
[src]
self,
catalog_name: &String,
schema_name: &String,
table_name: &String,
table_type: &String
) -> Result<Statement<'a, 'b, Executed, HasResult, AC>, Box<dyn Error>>
pub fn tables_str(
self,
catalog_name: &str,
schema_name: &str,
table_name: &str,
table_type: &str
) -> Result<Statement<'a, 'b, Executed, HasResult, AC>, Box<dyn Error>>
[src]
self,
catalog_name: &str,
schema_name: &str,
table_name: &str,
table_type: &str
) -> Result<Statement<'a, 'b, Executed, HasResult, AC>, Box<dyn Error>>
pub fn tables_opt_str(
self,
catalog_name: Option<&str>,
schema_name: Option<&str>,
table_name: Option<&str>,
table_type: &str
) -> Result<Statement<'a, 'b, Executed, HasResult, AC>, Box<dyn Error>>
[src]
self,
catalog_name: Option<&str>,
schema_name: Option<&str>,
table_name: Option<&str>,
table_type: &str
) -> Result<Statement<'a, 'b, Executed, HasResult, AC>, Box<dyn Error>>
pub fn exec_direct(
self,
statement_text: &str
) -> Result<ResultSetState<'a, 'b, Executed, AC>, Box<dyn Error>>
[src]
self,
statement_text: &str
) -> Result<ResultSetState<'a, 'b, Executed, AC>, Box<dyn Error>>
Executes a preparable statement, using the current values of the parameter marker variables if any parameters exist in the statement.
SQLExecDirect
is the fastest way to submit an SQL statement for one-time execution.
pub fn exec_direct_bytes(
self,
bytes: &[u8]
) -> Result<ResultSetState<'a, 'b, Executed, AC>, Box<dyn Error>>
[src]
self,
bytes: &[u8]
) -> Result<ResultSetState<'a, 'b, Executed, AC>, Box<dyn Error>>
Executes a preparable statement, using the current values of the parameter marker variables if any parameters exist in the statement.
SQLExecDirect
is the fastest way to submit an SQL statement for one-time execution.
impl<'a, 'b, S, AC: AutocommitMode> Statement<'a, 'b, S, HasResult, AC>
[src]
pub fn affected_row_count(&self) -> Result<i64>
[src]
pub fn num_result_cols(&self) -> Result<i16>
[src]
The number of columns in a result set
Can be called successfully only when the statement is in the prepared, executed, or positioned state. If the statement does not return columns the result will be 0.
pub fn describe_col(&self, idx: u16) -> Result<ColumnDescriptor>
[src]
Returns description struct for result set column with a given index. Note: indexing is starting from 1.
pub fn fetch<'s>(
&'s mut self
) -> Result<Option<Cursor<'s, 'a, 'b, S, AC>>, Box<dyn Error>>
[src]
&'s mut self
) -> Result<Option<Cursor<'s, 'a, 'b, S, AC>>, Box<dyn Error>>
Fetches the next rowset of data from the result set and returns data for all bound columns.
pub fn close_cursor(
self
) -> Result<Statement<'a, 'b, S, NoResult, AC>, Box<dyn Error>>
[src]
self
) -> Result<Statement<'a, 'b, S, NoResult, AC>, Box<dyn Error>>
Call this method to reuse the statement to execute another query.
For many drivers allocating new statements is expensive. So reusing a Statement
is usually
more efficient than freeing an existing and allocating a new one. However to reuse a
statement any open result sets must be closed.
Only call this method if you have already read the result set returned by the previous
query, or if you do no not intend to read it.
Example
let conn = env.connect("TestDataSource", "", "")?; let stmt = Statement::with_parent(&conn)?; let stmt = match stmt.exec_direct("CREATE TABLE STAGE (A TEXT, B TEXT);")?{ // Some drivers will return an empty result set. We need to close it before we can use // statement again. Data(stmt) => stmt.close_cursor()?, NoData(stmt) => stmt, }; let stmt = stmt.exec_direct("INSERT INTO STAGE (A, B) VALUES ('Hello', 'World');")?; //...
Trait Implementations
impl<'a, 'b, S, R, AC: AutocommitMode> Handle for Statement<'a, 'b, S, R, AC>
[src]
impl<'con, 'param, C, P, AC: AutocommitMode> Handle for Statement<'con, 'param, C, P, AC>
[src]
const HANDLE_TYPE: HandleType
[src]
fn handle(&self) -> SQLHANDLE
[src]
Auto Trait Implementations
impl<'a, 'b, S, R, AC> RefUnwindSafe for Statement<'a, 'b, S, R, AC> where
AC: RefUnwindSafe,
R: RefUnwindSafe,
S: RefUnwindSafe,
AC: RefUnwindSafe,
R: RefUnwindSafe,
S: RefUnwindSafe,
impl<'a, 'b, S, R, AC> !Send for Statement<'a, 'b, S, R, AC>
impl<'a, 'b, S, R, AC> !Sync for Statement<'a, 'b, S, R, AC>
impl<'a, 'b, S, R, AC> Unpin for Statement<'a, 'b, S, R, AC> where
AC: Unpin,
R: Unpin,
S: Unpin,
AC: Unpin,
R: Unpin,
S: Unpin,
impl<'a, 'b, S, R, AC> UnwindSafe for Statement<'a, 'b, S, R, AC> where
AC: UnwindSafe,
R: UnwindSafe,
S: UnwindSafe,
AC: UnwindSafe,
R: UnwindSafe,
S: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<H> Diagnostics for H where
H: Handle,
[src]
H: Handle,
pub fn diagnostics(
&self,
rec_number: i16,
message_text: &mut [u8]
) -> ReturnOption<DiagResult, ()>
[src]
&self,
rec_number: i16,
message_text: &mut [u8]
) -> ReturnOption<DiagResult, ()>
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,