Struct hdbconnect::Connection
source · pub struct Connection { /* private fields */ }
Expand description
A synchronous connection to the database.
Implementations§
source§impl Connection
impl Connection
sourcepub fn new<P>(params: P) -> Result<Connection, HdbError>where
P: IntoConnectParams,
pub fn new<P>(params: P) -> Result<Connection, HdbError>where
P: IntoConnectParams,
sourcepub fn with_configuration<P>(
params: P,
config: &ConnectionConfiguration
) -> Result<Connection, HdbError>where
P: IntoConnectParams,
pub fn with_configuration<P>(
params: P,
config: &ConnectionConfiguration
) -> Result<Connection, HdbError>where
P: IntoConnectParams,
Factory method for authenticated connections with given configuration.
§Errors
Several variants of HdbError
can occur.
sourcepub fn statement<S>(&self, stmt: S) -> Result<HdbResponse, HdbError>
pub fn statement<S>(&self, stmt: S) -> Result<HdbResponse, HdbError>
Executes a statement on the database.
This generic method can handle all kinds of calls,
and thus has the most generic return type.
In many cases it will be more convenient to use
one of the dedicated methods query()
, dml()
, exec()
below, which
internally convert the HdbResponse
to the
respective adequate simple result type.
§Example
let mut response = connection.statement(&statement_string)?; // HdbResponse
§Errors
Several variants of HdbError
can occur.
sourcepub fn prepare<S>(&self, stmt: S) -> Result<PreparedStatement, HdbError>
pub fn prepare<S>(&self, stmt: S) -> Result<PreparedStatement, HdbError>
Prepares a statement and returns a handle (a PreparedStatement
) to it.
Note that the PreparedStatement
keeps using the same database connection as
this Connection
.
§Example
let query_string = "select * from phrases where ID = ? and text = ?";
let statement = connection.prepare(query_string)?; //PreparedStatement
§Errors
Several variants of HdbError
can occur.
sourcepub fn prepare_and_execute<S, T>(
&self,
stmt: S,
input: &T
) -> Result<HdbResponse, HdbError>
pub fn prepare_and_execute<S, T>( &self, stmt: S, input: &T ) -> Result<HdbResponse, HdbError>
sourcepub fn spawn(&self) -> Result<Connection, HdbError>
pub fn spawn(&self) -> Result<Connection, HdbError>
Creates a new connection object with the same settings and authentication.
§Errors
Several variants of HdbError
can occur.
sourcepub fn multiple_statements_ignore_err<S>(&self, stmts: Vec<S>)
pub fn multiple_statements_ignore_err<S>(&self, stmts: Vec<S>)
Utility method to fire a couple of statements, ignoring errors and return values.
§Errors
Several variants of HdbError
can occur.
sourcepub fn multiple_statements<S>(&self, stmts: Vec<S>) -> Result<(), HdbError>
pub fn multiple_statements<S>(&self, stmts: Vec<S>) -> Result<(), HdbError>
Utility method to fire a couple of statements, ignoring their return
values; the method returns with the first error, or with ()
.
§Errors
Several variants of HdbError
can occur.
sourcepub fn pop_warnings(&self) -> Result<Option<Vec<ServerError>>, HdbError>
pub fn pop_warnings(&self) -> Result<Option<Vec<ServerError>>, HdbError>
Returns warnings that were returned from the server since the last call to this method.
§Errors
Only HdbError::Poison
can occur.
sourcepub fn is_auto_commit(&self) -> Result<bool, HdbError>
pub fn is_auto_commit(&self) -> Result<bool, HdbError>
sourcepub fn fetch_size(&self) -> Result<u32, HdbError>
pub fn fetch_size(&self) -> Result<u32, HdbError>
Returns the connection’s fetch size.
The default value is ConnectionConfiguration::DEFAULT_FETCH_SIZE
.
§Errors
Only HdbError::Poison
can occur.
sourcepub fn lob_read_length(&self) -> Result<u32, HdbError>
pub fn lob_read_length(&self) -> Result<u32, HdbError>
sourcepub fn lob_write_length(&self) -> Result<u32, HdbError>
pub fn lob_write_length(&self) -> Result<u32, HdbError>
sourcepub fn set_lob_write_length(&self, l: u32) -> Result<(), HdbError>
pub fn set_lob_write_length(&self, l: u32) -> Result<(), HdbError>
Sets the connection’s lob write length.
The intention of the parameter is to allow reducing the number of roundtrips to the database.
§Errors
Only HdbError::Poison
can occur.
sourcepub fn set_max_buffer_size(
&mut self,
max_buffer_size: usize
) -> Result<(), HdbError>
pub fn set_max_buffer_size( &mut self, max_buffer_size: usize ) -> Result<(), HdbError>
Sets the connection’s maximum buffer size.
See also ConnectionConfiguration::set_max_buffer_size
.
§Errors
Only HdbError::Poison
can occur.
sourcepub fn id(&self) -> Result<u32, HdbError>
pub fn id(&self) -> Result<u32, HdbError>
Returns the ID of the connection.
The ID is set by the server. Can be handy for logging.
§Errors
Only HdbError::Poison
can occur.
sourcepub fn server_usage(&self) -> Result<ServerUsage, HdbError>
pub fn server_usage(&self) -> Result<ServerUsage, HdbError>
Provides information about the the server-side resource consumption that is related to this Connection object.
§Errors
Only HdbError::Poison
can occur.
sourcepub fn statistics(&self) -> Result<ConnectionStatistics, HdbError>
pub fn statistics(&self) -> Result<ConnectionStatistics, HdbError>
Returns some statistics snapshot about what was done with this connection so far.
§Errors
Only HdbError::Poison
can occur.
sourcepub fn reset_statistics(&self) -> Result<(), HdbError>
pub fn reset_statistics(&self) -> Result<(), HdbError>
Reset the counters in the Connection’s statistic object.
sourcepub fn set_application<S>(&self, application: S) -> Result<(), HdbError>
pub fn set_application<S>(&self, application: S) -> Result<(), HdbError>
Sets client information into a session variable on the server.
Example:
connection.set_application("MyApp, built in rust")?;
§Errors
Only HdbError::Poison
can occur.
sourcepub fn set_application_user<S>(&self, appl_user: S) -> Result<(), HdbError>
pub fn set_application_user<S>(&self, appl_user: S) -> Result<(), HdbError>
Sets client information into a session variable on the server.
Example:
connection.set_application_user("K2209657")?;
§Errors
Only HdbError::Poison
can occur.
sourcepub fn set_application_version<S>(&self, version: S) -> Result<(), HdbError>
pub fn set_application_version<S>(&self, version: S) -> Result<(), HdbError>
Sets client information into a session variable on the server.
Example:
connection.set_application_version("5.3.23")?;
§Errors
Only HdbError::Poison
can occur.
sourcepub fn set_application_source<S>(&self, source: S) -> Result<(), HdbError>
pub fn set_application_source<S>(&self, source: S) -> Result<(), HdbError>
Sets client information into a session variable on the server.
Example:
connection.set_application_source("update_customer.rs")?;
§Errors
Only HdbError::Poison
can occur.
sourcepub fn get_resource_manager(&self) -> Box<dyn ResourceManager>
pub fn get_resource_manager(&self) -> Box<dyn ResourceManager>
Returns an implementation of dist_tx::rm::ResourceManager
that is
based on this connection.
sourcepub fn execute_with_debuginfo<S>(
&self,
stmt: S,
module: S,
line: u32
) -> Result<HdbResponse, HdbError>
pub fn execute_with_debuginfo<S>( &self, stmt: S, module: S, line: u32 ) -> Result<HdbResponse, HdbError>
Tools like debuggers can provide additional information while stepping through a source.
§Errors
Several variants of HdbError
can occur.
sourcepub fn get_database_name(&self) -> Result<String, HdbError>
pub fn get_database_name(&self) -> Result<String, HdbError>
(MDC) Database name.
§Errors
Errors are unlikely to occur.
HdbError::ImplDetailed
if the database name was not provided by the database server.HdbError::Poison
if the shared mutex of the inner connection object is poisened.
sourcepub fn get_system_id(&self) -> Result<String, HdbError>
pub fn get_system_id(&self) -> Result<String, HdbError>
The system id is set by the server with the SAPSYSTEMNAME of the connected instance (for tracing and supportability purposes).
§Errors
Errors are unlikely to occur.
HdbError::ImplDetailed
if the system id was not provided by the database server.HdbError::Poison
if the shared mutex of the inner connection object is poisened.
sourcepub fn client_info(&self) -> Result<Vec<(String, String)>, HdbError>
pub fn client_info(&self) -> Result<Vec<(String, String)>, HdbError>
Returns the information that is given to the server as client context.
§Errors
Only HdbError::Poison
can occur.
sourcepub fn connect_string(&self) -> Result<String, HdbError>
pub fn connect_string(&self) -> Result<String, HdbError>
Returns a connect url (excluding the password) that reflects the options that were used to establish this connection.
§Errors
Only HdbError::Poison
can occur.
sourcepub fn get_full_version_string(&self) -> Result<String, HdbError>
pub fn get_full_version_string(&self) -> Result<String, HdbError>
HANA Full version string.
§Errors
Errors are unlikely to occur.
HdbError::ImplDetailed
if the version string was not provided by the database server.HdbError::Poison
if the shared mutex of the inner connection object is poisened.