pub struct Statement<'con, 'b, S, R> { /* fields omitted */ }
A Statement
can be used to execute queries and retrieves results.
Binds a parameter to a parameter marker in an SQL statement.
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 derefernce an invalid pointer
during execution.
parameter_index
- Index of the marker to bind to the parameter. Starting at 1
value
- Reference to bind to the marker
let env = create_environment_v3().map_err(|e| e.unwrap())?;
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)? {
}
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.
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.
let env = create_environment_v3().map_err(|e| e.unwrap())?;
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>) -> Result<Statement<'a, 'a, Prepared, NoResult>>{
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)?
}
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.
let env = create_environment_v3().map_err(|e| e.unwrap())?;
let conn = env.connect("TestDataSource", "", "")?;
let stmt = Statement::with_parent(&conn)?;
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.
Returns description struct for result set column with a given index. Note: indexing is starting from 1.
Executes a prepared statement.
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.
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.
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.
Returns description struct for result set column with a given index. Note: indexing is starting from 1.
Fetches the next rowset of data from the result set and returns data for all bound columns.
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 alloctaing 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.
let env = create_environment_v3().map_err(|e| e.unwrap())?;
let conn = env.connect("TestDataSource", "", "")?;
let stmt = Statement::with_parent(&conn)?;
let stmt = match stmt.exec_direct("CREATE TABLE STAGE (A TEXT, B TEXT);")?{
Data(stmt) => stmt.close_cursor()?,
NoData(stmt) => stmt,
};
let stmt = stmt.exec_direct("INSERT INTO STAGE (A, B) VALUES ('Hello', 'World');")?;
Returns a valid handle to the odbc type.
Used to identify the type of the handle in various functions of the ODBC C interface
Returns a ptr to the wrapped ODBC Object
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Returns the current values of multiple fields of a diagnostic record that contains error, warning, and status information. Read more