Struct hdbconnect::Connection

source ·
pub struct Connection { /* private fields */ }
Expand description

A synchronous connection to the database.

Implementations§

source§

impl Connection

source

pub fn new<P>(params: P) -> Result<Connection, HdbError>

Factory method for authenticated connections.

§Example
use hdbconnect::Connection;
let conn = Connection::new("hdbsql://my_user:my_passwd@the_host:2222").unwrap();
§Errors

Several variants of HdbError can occur.

source

pub fn with_configuration<P>( params: P, config: &ConnectionConfiguration ) -> Result<Connection, HdbError>

Factory method for authenticated connections with given configuration.

§Errors

Several variants of HdbError can occur.

source

pub fn statement<S>(&self, stmt: S) -> Result<HdbResponse, HdbError>
where S: AsRef<str>,

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.

source

pub fn query<S>(&self, stmt: S) -> Result<ResultSet, HdbError>
where S: AsRef<str>,

Executes a statement and expects a single ResultSet.

Should be used for query statements (like “SELECT …”) which return a single resultset.

§Example
let mut rs = connection.query(&statement_string)?; // ResultSet
§Errors

Several variants of HdbError can occur.

source

pub fn dml<S>(&self, stmt: S) -> Result<usize, HdbError>
where S: AsRef<str>,

Executes a statement and expects a single number of affected rows.

Should be used for DML statements only, i.e., INSERT, UPDATE, DELETE, UPSERT.

§Example
let count = connection.dml(&statement_string)?; //usize
§Errors

Several variants of HdbError can occur.

source

pub fn exec<S>(&self, stmt: S) -> Result<(), HdbError>
where S: AsRef<str>,

Executes a statement and expects a plain success.

Should be used for SQL commands like “ALTER SYSTEM …”.

§Example
connection.exec(&statement_string)?;
§Errors

Several variants of HdbError can occur.

source

pub fn prepare<S>(&self, stmt: S) -> Result<PreparedStatement, HdbError>
where S: AsRef<str>,

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.

source

pub fn prepare_and_execute<S, T>( &self, stmt: S, input: &T ) -> Result<HdbResponse, HdbError>
where S: AsRef<str>, T: Serialize,

Prepares a statement and executes it a single time.

§Errors

Several variants of HdbError can occur.

source

pub fn commit(&self) -> Result<(), HdbError>

Commits the current transaction.

§Errors

Several variants of HdbError can occur.

source

pub fn rollback(&self) -> Result<(), HdbError>

Rolls back the current transaction.

§Errors

Several variants of HdbError can occur.

source

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.

source

pub fn multiple_statements_ignore_err<S>(&self, stmts: Vec<S>)
where S: AsRef<str>,

Utility method to fire a couple of statements, ignoring errors and return values.

§Errors

Several variants of HdbError can occur.

source

pub fn multiple_statements<S>(&self, stmts: Vec<S>) -> Result<(), HdbError>
where S: AsRef<str>,

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.

source

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.

source

pub fn set_auto_commit(&self, ac: bool) -> Result<(), HdbError>

Sets the connection’s auto-commit behavior.

§Errors

Only HdbError::Poison can occur.

source

pub fn is_auto_commit(&self) -> Result<bool, HdbError>

Returns the connection’s auto-commit behavior.

§Errors

Only HdbError::Poison can occur.

source

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.

source

pub fn set_fetch_size(&self, fetch_size: u32) -> Result<(), HdbError>

Sets the connection’s fetch size.

§Errors

Only HdbError::Poison can occur.

source

pub fn read_timeout(&self) -> Result<Option<Duration>, HdbError>

Returns the connection’s read timeout.

§Errors

Only HdbError::Poison can occur.

source

pub fn set_read_timeout( &self, read_timeout: Option<Duration> ) -> Result<(), HdbError>

Sets the connection’s read timeout.

§Errors

Only HdbError::Poison can occur.

source

pub fn lob_read_length(&self) -> Result<u32, HdbError>

Returns the connection’s lob read length.

§Errors

Only HdbError::Poison can occur.

source

pub fn set_lob_read_length(&self, l: u32) -> Result<(), HdbError>

Sets the connection’s lob read length.

§Errors

Only HdbError::Poison can occur.

source

pub fn lob_write_length(&self) -> Result<u32, HdbError>

Returns the connection’s lob write length.

§Errors

Only HdbError::Poison can occur.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn reset_statistics(&self) -> Result<(), HdbError>

Reset the counters in the Connection’s statistic object.

source

pub fn set_application<S>(&self, application: S) -> Result<(), HdbError>
where S: AsRef<str>,

Sets client information into a session variable on the server.

Example:

connection.set_application("MyApp, built in rust")?;
§Errors

Only HdbError::Poison can occur.

source

pub fn set_application_user<S>(&self, appl_user: S) -> Result<(), HdbError>
where S: AsRef<str>,

Sets client information into a session variable on the server.

Example:

connection.set_application_user("K2209657")?;
§Errors

Only HdbError::Poison can occur.

source

pub fn set_application_version<S>(&self, version: S) -> Result<(), HdbError>
where S: AsRef<str>,

Sets client information into a session variable on the server.

Example:

connection.set_application_version("5.3.23")?;
§Errors

Only HdbError::Poison can occur.

source

pub fn set_application_source<S>(&self, source: S) -> Result<(), HdbError>
where S: AsRef<str>,

Sets client information into a session variable on the server.

Example:

connection.set_application_source("update_customer.rs")?;
§Errors

Only HdbError::Poison can occur.

source

pub fn get_resource_manager(&self) -> Box<dyn ResourceManager>

Returns an implementation of dist_tx::rm::ResourceManager that is based on this connection.

source

pub fn execute_with_debuginfo<S>( &self, stmt: S, module: S, line: u32 ) -> Result<HdbResponse, HdbError>
where S: AsRef<str>,

Tools like debuggers can provide additional information while stepping through a source.

§Errors

Several variants of HdbError can occur.

source

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.
source

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.
source

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.

source

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.

source

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.
source

pub fn is_broken(&self) -> Result<bool, HdbError>

Returns true if the connection object losts its TCP connection.

Trait Implementations§

source§

impl Debug for Connection

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V