Struct odbc_api::handles::Connection
source · pub struct Connection<'c> { /* private fields */ }
Expand description
The connection handle references storage of all information about the connection to the data source, including status, transaction state, and error information.
Connection is not Sync
, this implies that many methods which one would suspect should take
&mut self
are actually &self
. This is important if several statement exists which borrow
the same connection.
Implementations§
source§impl<'c> Connection<'c>
impl<'c> Connection<'c>
sourcepub unsafe fn new(handle: HDbc) -> Self
pub unsafe fn new(handle: HDbc) -> Self
Safety
Call this method only with a valid (successfully allocated) ODBC connection handle.
sourcepub fn connect(
&mut self,
data_source_name: &SqlText<'_>,
user: &SqlText<'_>,
pwd: &SqlText<'_>
) -> SqlResult<()>
pub fn connect( &mut self, data_source_name: &SqlText<'_>, user: &SqlText<'_>, pwd: &SqlText<'_> ) -> SqlResult<()>
Establishes connections to a driver and a data source.
Arguments
data_source_name
- Data source name. The data might be located on the same computer as the program, or on another computer somewhere on a network.user
- User identifier.pwd
- Authentication string (typically the password).
sourcepub fn connect_with_connection_string(
&mut self,
connection_string: &SqlText<'_>
) -> SqlResult<()>
pub fn connect_with_connection_string( &mut self, connection_string: &SqlText<'_> ) -> SqlResult<()>
An alternative to connect
. It supports data sources that require more connection
information than the three arguments in connect
and data sources that are not defined in
the system information.
sourcepub unsafe fn driver_connect(
&mut self,
connection_string: &SqlText<'_>,
parent_window: HWnd,
completed_connection_string: &mut OutputStringBuffer,
driver_completion: DriverConnectOption
) -> SqlResult<()>
pub unsafe fn driver_connect( &mut self, connection_string: &SqlText<'_>, parent_window: HWnd, completed_connection_string: &mut OutputStringBuffer, driver_completion: DriverConnectOption ) -> SqlResult<()>
An alternative to connect
for connecting with a connection string. Allows for completing
a connection string with a GUI prompt on windows.
Return
SqlResult::NoData
in case the prompt completing the connection string has been aborted.
Safety
parent_window
must either be a valid window handle or NULL
.
sourcepub fn disconnect(&mut self) -> SqlResult<()>
pub fn disconnect(&mut self) -> SqlResult<()>
Disconnect from an ODBC data source.
sourcepub fn allocate_statement(&self) -> SqlResult<StatementImpl<'_>>
pub fn allocate_statement(&self) -> SqlResult<StatementImpl<'_>>
Allocate a new statement handle. The Statement
must not outlive the Connection
.
sourcepub fn set_autocommit(&self, enabled: bool) -> SqlResult<()>
pub fn set_autocommit(&self, enabled: bool) -> SqlResult<()>
Specify the transaction mode. By default, ODBC transactions are in auto-commit mode (unless SQLSetConnectAttr and SQLSetConnectOption are not supported, which is unlikely). Switching from manual-commit mode to auto-commit mode automatically commits any open transaction on the connection.
sourcepub fn set_login_timeout_sec(&self, timeout: u32) -> SqlResult<()>
pub fn set_login_timeout_sec(&self, timeout: u32) -> SqlResult<()>
Number of seconds to wait for a login request to complete before returning to the
application. The default is driver-dependent. If 0
the timeout is dasabled and a
connection attempt will wait indefinitely.
If the specified timeout exceeds the maximum login timeout in the data source, the driver substitutes that value and uses the maximum login timeout instead.
This corresponds to the SQL_ATTR_LOGIN_TIMEOUT
attribute in the ODBC specification.
See: https://learn.microsoft.com/en-us/sql/odbc/reference/syntax/sqlsetconnectattr-function
sourcepub fn fetch_database_management_system_name(
&self,
buf: &mut Vec<SqlChar>
) -> SqlResult<()>
pub fn fetch_database_management_system_name( &self, buf: &mut Vec<SqlChar> ) -> SqlResult<()>
Fetch the name of the database management system used by the connection and store it into
the provided buf
.
sourcepub fn max_catalog_name_len(&self) -> SqlResult<u16>
pub fn max_catalog_name_len(&self) -> SqlResult<u16>
Maximum length of catalog names.
sourcepub fn max_schema_name_len(&self) -> SqlResult<u16>
pub fn max_schema_name_len(&self) -> SqlResult<u16>
Maximum length of schema names.
sourcepub fn max_table_name_len(&self) -> SqlResult<u16>
pub fn max_table_name_len(&self) -> SqlResult<u16>
Maximum length of table names.
sourcepub fn max_column_name_len(&self) -> SqlResult<u16>
pub fn max_column_name_len(&self) -> SqlResult<u16>
Maximum length of column names.
Trait Implementations§
source§impl<'c> AsHandle for Connection<'c>
impl<'c> AsHandle for Connection<'c>
source§fn as_handle(&self) -> Handle
fn as_handle(&self) -> Handle
source§fn handle_type(&self) -> HandleType
fn handle_type(&self) -> HandleType
as_handle
. This is a method rather than a constant
in order to make the type object safe.