pub struct Environment<V: VersionOption> { /* private fields */ }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
See: [Environment Handles in the ODBC Reference][1] [1]: https://docs.microsoft.com/sql/odbc/reference/develop-app/environment-handles
Implementations§
Source§impl<V: VersionOption> Environment<V>
impl<V: VersionOption> Environment<V>
Source§impl<V: Version> Environment<V>
impl<V: Version> Environment<V>
Sourcepub fn data_sources(
&mut self,
direction: FetchOrientation,
server_name: &mut [u8],
description: &mut [u8],
) -> ReturnOption<(SQLSMALLINT, SQLSMALLINT)>
pub fn data_sources( &mut self, direction: FetchOrientation, server_name: &mut [u8], description: &mut [u8], ) -> ReturnOption<(SQLSMALLINT, SQLSMALLINT)>
Fills buffers with information about the available datasources
A 32 / 64 Bit Application will only return information about either 32 or 64 Bit DataSources.
§Returns
(server_name_length, description_length)
See [SQLDataSources][1] [1]: https://docs.microsoft.com/sql/odbc/reference/syntax/sqldatasources-function
Examples found in repository?
8fn main() {
9
10 let env = Environment::new().unwrap();
11 let mut env = env.declare_version_3().unwrap();
12
13 let mut server_name = [0; 512];
14 let mut description = [0; 512];
15
16 println!("ODBC Data Sources:");
17
18 loop {
19 let (name_length, description_length) =
20 match env.data_sources(SQL_FETCH_NEXT, &mut server_name, &mut description) {
21 ReturnOption::Success(v) => v,
22 ReturnOption::Info(_) => panic!("Buffers not large enough. Truncation occurred."),
23 ReturnOption::NoData(()) => break,
24 ReturnOption::Error(()) => {
25 panic!("Error occurred. Could use diagnostics to learn more")
26 }
27 };
28
29 println!(
30 "\tName: {}\n\tDescription: {}\n",
31 from_utf8(&server_name[..(name_length as usize)]).unwrap(),
32 from_utf8(&description[..(description_length as usize)]).unwrap()
33 );
34 }
35}Sourcepub fn drivers(
&mut self,
direction: FetchOrientation,
description: &mut [u8],
attributes: &mut [u8],
) -> ReturnOption<(SQLSMALLINT, SQLSMALLINT)>
pub fn drivers( &mut self, direction: FetchOrientation, description: &mut [u8], attributes: &mut [u8], ) -> ReturnOption<(SQLSMALLINT, SQLSMALLINT)>
Fills buffers with information about the available datasources
A 32 / 64 Bit Application will only return information about either 32 or 64 Bit DataSources.
§Returns
(description_length, attributes_length)
See [SQLDrivers][1] [1]: https://docs.microsoft.com/sql/odbc/reference/syntax/sqldrivers-function
Examples found in repository?
8fn main() {
9
10 let env = Environment::new().unwrap();
11 let mut env = env.declare_version_3().unwrap();
12
13 let mut description = [0; 512];
14 let mut attributes = [0; 512];
15
16 println!("ODBC Drivers:");
17
18 loop {
19 let (description_length, attributes_length) =
20 match env.drivers(SQL_FETCH_NEXT, &mut description, &mut attributes) {
21 ReturnOption::Success(v) => v,
22 ReturnOption::Info(_) => panic!("Buffers not large enough. Truncation occurred."),
23 ReturnOption::NoData(()) => break,
24 ReturnOption::Error(()) => {
25 panic!("Error occurred. Could use diagnostics to learn more")
26 }
27 };
28
29 println!(
30 "\tDescription: {}\n\tAttributes: {}\n",
31 from_utf8(&description[..(description_length as usize)]).unwrap(),
32 from_utf8(&attributes[..(attributes_length as usize)]).unwrap()
33 );
34 }
35}Source§impl Environment<NoVersion>
impl Environment<NoVersion>
Sourcepub fn new() -> Return<Self>
pub fn new() -> Return<Self>
Allocates a new Environment
Examples found in repository?
More examples
6fn main() {
7
8 let env = Environment::new().unwrap();
9 let env = env.declare_version_3().unwrap();
10 let conn = connect(&env);
11 let mut stmt = prepare_query(&conn);
12 for &year in [1968, 1993].iter() {
13 let result_set = execute_query(stmt, year);
14 stmt = print_fields(result_set);
15 println!("");
16 }
17}5fn main() {
6 let env = Environment::new().unwrap();
7 let env = env.declare_version_3().unwrap();
8
9 let ds = DataSource::with_parent(&env).unwrap();
10 let conn = ds.connect("TestDataSource", "", "").unwrap();
11 let mut conn = conn.disable_autocommit().unwrap();
12
13 {
14 //Any statement now will start transaction which could be ended with conn.commit() or conn.rollback()
15 //If either commit or rollback was not called before connection drop automatic rollback will be issued
16 let stmt = Statement::with_parent(&conn).unwrap();
17 let res = stmt.exec_direct("SELECT 'HELLO' FROM MOVIES");
18 println!("Result {:?}", res);
19 }
20
21 let end_tx_result = conn.commit();
22
23 println!("End TX result {:?}", end_tx_result);
24}8fn main() {
9
10 let env = Environment::new().unwrap();
11 let mut env = env.declare_version_3().unwrap();
12
13 let mut server_name = [0; 512];
14 let mut description = [0; 512];
15
16 println!("ODBC Data Sources:");
17
18 loop {
19 let (name_length, description_length) =
20 match env.data_sources(SQL_FETCH_NEXT, &mut server_name, &mut description) {
21 ReturnOption::Success(v) => v,
22 ReturnOption::Info(_) => panic!("Buffers not large enough. Truncation occurred."),
23 ReturnOption::NoData(()) => break,
24 ReturnOption::Error(()) => {
25 panic!("Error occurred. Could use diagnostics to learn more")
26 }
27 };
28
29 println!(
30 "\tName: {}\n\tDescription: {}\n",
31 from_utf8(&server_name[..(name_length as usize)]).unwrap(),
32 from_utf8(&description[..(description_length as usize)]).unwrap()
33 );
34 }
35}Sourcepub fn declare_version<V: Version>(
self,
) -> Return<Environment<V>, Environment<NoVersion>>
pub fn declare_version<V: Version>( self, ) -> Return<Environment<V>, Environment<NoVersion>>
Before an application allocates a connection which specification it follows. Currently these bindings only support ODBC 3.x.
It is valid to specify ODBC 3.x even then connecting to an ODBC 2.x driver. Applications must however avoid calling 3.x functionality on 2.x drivers. Since drivers are connected at runtime, these kind of errors can not be catched by the type system.
Sourcepub fn declare_version_3_8(
self,
) -> Return<Environment<Odbc3m8>, Environment<NoVersion>>
pub fn declare_version_3_8( self, ) -> Return<Environment<Odbc3m8>, Environment<NoVersion>>
Before an application allocates a connection which specification it follows. Currently these bindings only support ODBC 3.x.
It is valid to specify ODBC 3.x even then connecting to an ODBC 2.x driver. Applications must however avoid calling 3.x functionality on 2.x drivers. Since drivers are connected at runtime, these kind of errors can not be catched by the type system.
This method is a shorthand for declare_version::<Odbc3m8>.
Sourcepub fn declare_version_3(
self,
) -> Return<Environment<Odbc3>, Environment<NoVersion>>
pub fn declare_version_3( self, ) -> Return<Environment<Odbc3>, Environment<NoVersion>>
Before an application allocates a connection which specification it follows. Currently these bindings only support ODBC 3.x.
It is valid to specify ODBC 3.x even then connecting to an ODBC 2.x driver. Applications must however avoid calling 3.x functionality on 2.x drivers. Since drivers are connected at runtime, these kind of errors can not be catched by the type system.
This method is a shorthand for declare_version::<Odbc3>.
Examples found in repository?
More examples
6fn main() {
7
8 let env = Environment::new().unwrap();
9 let env = env.declare_version_3().unwrap();
10 let conn = connect(&env);
11 let mut stmt = prepare_query(&conn);
12 for &year in [1968, 1993].iter() {
13 let result_set = execute_query(stmt, year);
14 stmt = print_fields(result_set);
15 println!("");
16 }
17}5fn main() {
6 let env = Environment::new().unwrap();
7 let env = env.declare_version_3().unwrap();
8
9 let ds = DataSource::with_parent(&env).unwrap();
10 let conn = ds.connect("TestDataSource", "", "").unwrap();
11 let mut conn = conn.disable_autocommit().unwrap();
12
13 {
14 //Any statement now will start transaction which could be ended with conn.commit() or conn.rollback()
15 //If either commit or rollback was not called before connection drop automatic rollback will be issued
16 let stmt = Statement::with_parent(&conn).unwrap();
17 let res = stmt.exec_direct("SELECT 'HELLO' FROM MOVIES");
18 println!("Result {:?}", res);
19 }
20
21 let end_tx_result = conn.commit();
22
23 println!("End TX result {:?}", end_tx_result);
24}8fn main() {
9
10 let env = Environment::new().unwrap();
11 let mut env = env.declare_version_3().unwrap();
12
13 let mut server_name = [0; 512];
14 let mut description = [0; 512];
15
16 println!("ODBC Data Sources:");
17
18 loop {
19 let (name_length, description_length) =
20 match env.data_sources(SQL_FETCH_NEXT, &mut server_name, &mut description) {
21 ReturnOption::Success(v) => v,
22 ReturnOption::Info(_) => panic!("Buffers not large enough. Truncation occurred."),
23 ReturnOption::NoData(()) => break,
24 ReturnOption::Error(()) => {
25 panic!("Error occurred. Could use diagnostics to learn more")
26 }
27 };
28
29 println!(
30 "\tName: {}\n\tDescription: {}\n",
31 from_utf8(&server_name[..(name_length as usize)]).unwrap(),
32 from_utf8(&description[..(description_length as usize)]).unwrap()
33 );
34 }
35}