use crate::Connection;
use std::error::Error;
pub struct Environment {
env: odbc_api::Environment,
}
impl Environment {
pub fn connect_with_connection_string_and_custom_options<'a>(
&self,
connection_string: &str,
connection_options: odbc_api::ConnectionOptions,
) -> Result<Connection, Box<dyn Error>> {
Ok(Connection::new(self
.env
.connect_with_connection_string(connection_string, connection_options)?))
}
pub fn connect_with_connection_string<'a>(
&self,
connection_string: &str,
) -> Result<Connection, Box<dyn Error>> {
self.connect_with_connection_string_and_custom_options(
connection_string,
odbc_api::ConnectionOptions::default(),
)
}
pub fn connect<'a>(
&self,
data_source_name: &str,
user: &str,
pwd: &str
) -> Result<Connection, Box<dyn Error>> {
self.connect_with_custom_options(data_source_name, user, pwd, odbc_api::ConnectionOptions::default())
}
pub fn connect_with_custom_options<'a>(
&self,
data_source_name: &str,
user: &str,
pwd: &str,
options: odbc_api::ConnectionOptions
) -> Result<Connection, Box<dyn Error>> {
Ok(Connection::new(self
.env
.connect(data_source_name, user, pwd, options)?))
}
pub fn new() -> Result<Self, Box<dyn Error>> {
Ok(Environment {
env: odbc_api::Environment::new()?,
})
}
}