Struct odbc_api::handles::Environment [−][src]
pub struct Environment { /* fields omitted */ }
Expand description
An Environment
is a global context, in which to access data.
Associated with an Environment
is any information that is global in nature, such as:
- The
Environment
’s state - The current environment-level diagnostics
- The handles of connections currently allocated on the environment
- The current stetting of each environment attribute
Implementations
Enable or disable (default) connection pooling for ODBC connections. Call this function before creating the ODBC environment for which you want to enable connection pooling.
See: https://docs.microsoft.com/en-us/sql/odbc/reference/develop-app/driver-manager-connection-pooling
Safety
An ODBC driver must be fully thread-safe, and connections must not have thread affinity to support connection pooling. This means the driver is able to handle a call on any thread at any time and is able to connect on one thread, to use the connection on another thread, and to disconnect on a third thread.
An allocated ODBC Environment handle
Safety
There may only be one Odbc environment in any process at any time. Take care using this function in unit tests, as these run in parallel by default in Rust. Also no library should probably wrap the creation of an odbc environment into a safe function call. This is because using two of these “safe” libraries at the same time in different parts of your program may lead to race condition thus violating Rust’s safety guarantees.
Creating one environment in your binary is safe however.
Declares which Version of the ODBC API we want to use. This is the first thing that should be done with any ODBC environment.
Allocate a new connection handle. The Connection
must not outlive the Environment
.
pub unsafe fn drivers_buffer_fill(
&self,
direction: FetchOrientation,
buffer_description: &mut Vec<u16>,
buffer_attributes: &mut Vec<u16>
) -> Result<bool, Error>
pub unsafe fn drivers_buffer_fill(
&self,
direction: FetchOrientation,
buffer_description: &mut Vec<u16>,
buffer_attributes: &mut Vec<u16>
) -> Result<bool, Error>
List drivers descriptions and driver attribute keywords.
Safety
Callers need to make sure only one thread is iterating over driver information at a time.
Method changes environment state. This method would be safe to call via an exclusive &mut
reference, yet that would restrict usecases. E.g. requesting information would only be
possible before connections borrow a reference.
Parameters
direction
: Determines whether the Driver Manager fetches the next driver in the list (FetchOrientation::Next
) or whether the search starts from the beginning of the list (FetchOrientation::First
).buffer_description
: In casetrue
is returned this buffer is filled with the description of the driver.buffer_attributes
: In casetrue
is returned this buffer is filled with a list of key value attributes. E.g.:"key1=value1\0key2=value2\0\0"
.
Use Environment::drivers_buffer_len
to determine buffer lengths.
See SQLDrivers
pub unsafe fn drivers_buffer_len(
&self,
direction: FetchOrientation
) -> Result<Option<(i16, i16)>, Error>
pub unsafe fn drivers_buffer_len(
&self,
direction: FetchOrientation
) -> Result<Option<(i16, i16)>, Error>
Use together with Environment::drivers_buffer_fill
to list drivers descriptions and driver attribute
keywords.
Safety
Callers need to make sure only one thread is iterating over driver information at a time.
Method changes environment state. This method would be safe to call via an exclusive &mut
reference, yet that would restrict usecases. E.g. requesting information would only be
possible before connections borrow a reference.
Parameters
direction
: Determines whether the Driver Manager fetches the next driver in the list (FetchOrientation::Next
) or whether the search starts from the beginning of the list (FetchOrientation::First
).
Return
(driver description length, attribute length)
. Length is in characters minus terminating
terminating zero.
See SQLDrivers
pub unsafe fn data_source_buffer_len(
&self,
direction: FetchOrientation
) -> Result<Option<(i16, i16)>, Error>
pub unsafe fn data_source_buffer_len(
&self,
direction: FetchOrientation
) -> Result<Option<(i16, i16)>, Error>
Use together with Environment::data_source_buffer_fill
to list drivers descriptions and
driver attribute keywords.
Safety
Callers need to make sure only one thread is iterating over data source information at a
time. Method changes environment state. This method would be safe to call via an exclusive
&mut
reference, yet that would restrict usecases. E.g. requesting information would only
be possible before connections borrow a reference.
Parameters
direction
: Determines whether the Driver Manager fetches the next driver in the list (FetchOrientation::Next
) or whether the search starts from the beginning of the list (FetchOrientation::First
,FetchOrientation::FirstSystem
,FetchOrientation::FirstUser
).
Return
(server name length, description length)
. Length is in characters minus terminating zero.
pub unsafe fn data_source_buffer_fill(
&self,
direction: FetchOrientation,
buffer_name: &mut Vec<u16>,
buffer_description: &mut Vec<u16>
) -> Result<bool, Error>
pub unsafe fn data_source_buffer_fill(
&self,
direction: FetchOrientation,
buffer_name: &mut Vec<u16>,
buffer_description: &mut Vec<u16>
) -> Result<bool, Error>
List drivers descriptions and driver attribute keywords.
Safety
Callers need to make sure only one thread is iterating over data source information at a
time. Method changes environment state. This method would be safe to call via an exclusive
&mut
reference, yet that would restrict usecases. E.g. requesting information would only
be possible before connections borrow a reference.
Parameters
direction
: Determines whether the Driver Manager fetches the next driver in the list (FetchOrientation::Next
) or whether the search starts from the beginning of the list (FetchOrientation::First
,FetchOrientation::FirstSystem
,FetchOrientation::FirstUser
).buffer_name
: In casetrue
is returned this buffer is filled with the name of the datasource.buffer_description
: In casetrue
is returned this buffer is filled with a description of the datasource (i.e. Driver name).
Use Environment::data_source_buffer_len
to determine buffer lengths.
Trait Implementations
The raw underlying ODBC handle used to talk to the ODBC C API. The handle must be valid.
The type of the ODBC handle returned by as_handle
.