Made to Order Software Corporation Logo

odbcpp: odbcpp::environment Class Reference

An ODBC environment. More...

#include <environment.h>

Inheritance diagram for odbcpp::environment:
Collaboration diagram for odbcpp::environment:

List of all members.

Classes

class  data_source_t
 Holds information about a data source. More...

Public Types

enum  data_source_type_t { DATA_SOURCE_TYPE_ALL, DATA_SOURCE_TYPE_USER, DATA_SOURCE_TYPE_SYSTEM }
 

The type of data source to get.

More...

typedef std::vector
< data_source_t
data_source_vector_t
 Defines a vector of data source information (server/description pairs).

Public Member Functions

void commit ()
 Immediately commit all the transactions.

 environment (SQLUINTEGER version=SQL_OV_ODBC3)
 Allocate an ODBC environment.

void get_data_source (data_source_type_t type, data_source_vector_t &sources)
 Read the data source names and descriptions.

void rollback ()
 Immediately rollback all the transactions.

void set_attr (SQLINTEGER attr, SQLPOINTER ptr, SQLINTEGER length)
 Set a pointer environment attribute.

void set_attr (SQLINTEGER attr, SQLINTEGER integer)
 Set an integer environment attribute.


Detailed Description

An ODBC environment.

Whenever you need to access one or more databases, you first need to create an environment. Then create one or more connections to different databases.

Note that it is possible to create multiple environments, in which case the commit() and rollback() calls will be specific to the connections of each specific environment.

Definition at line 34 of file environment.h.


Member Typedef Documentation

Defines a vector of data source information (server/description pairs).

Definition at line 47 of file environment.h.


Member Enumeration Documentation

The type of data source to get.

This values defined by this enumeration are used to read all or a specific data source.

See also:
get_data_source()
Enumerator:
DATA_SOURCE_TYPE_ALL 

Read any data source.

Use this value with get_data_source() to read the USER and SYSTEM data sources.

DATA_SOURCE_TYPE_USER 

Read the USER data sources.

Use this value with get_data_source() to read the USER data sources. (i.e. the user defined odbc.ini file, usually ~/.odbc.ini)

DATA_SOURCE_TYPE_SYSTEM 

Read the SYSTEM data sources.

Use this value with get_data_source() to read the SYSTEM data sources. (i.e. the system defined odbc.ini file, usually /etc/odbc.ini)

Definition at line 37 of file environment.h.


Constructor & Destructor Documentation

odbcpp::environment::environment ( SQLUINTEGER  version = SQL_OV_ODBC3  ) 

Allocate an ODBC environment.

This function initializes an environment object.

It immediately allocates an ODBC environment and thus it can right away be used to create connections.

When creating an environment, it is required to specify the version to use. Because of this, the environment constructor forces you to specify the version. The version can be set to SQL_OV_ODBC2 or SQL_OV_ODBC3. Version 1 won't work.

At this time, the default version is SQL_OV_ODBC3.

Parameters:
[in] version The version to use with the environment.
Exceptions:
odbc_exception_no_environment If the allocation fails, an odbc_exception_no_environment will be thrown.

Definition at line 101 of file environment.cpp.

References odbcpp::handle::check(), odbcpp::handle::f_handle, odbcpp::handle::f_handle_type, and set_attr().


Member Function Documentation

void odbcpp::environment::commit (  ) 

Immediately commit all the transactions.

This function sends a commit to all the transactions of all the connections present in this environment.

If there are no connections, nothing happens.

Exceptions:
odbcpp_error And odbcpp_error will be thrown if the SQL function returns an error.

Definition at line 223 of file environment.cpp.

References odbcpp::handle::check(), odbcpp::handle::f_handle, and odbcpp::handle::f_handle_type.

void odbcpp::environment::get_data_source ( data_source_type_t  type,
data_source_vector_t sources 
)

Read the data source names and descriptions.

This function reads the data source names and descriptions of all the DSN, the User DSN or the Sytem DSN.

The name of the server, as defined here, is the name of the section defined between [ and ] in the system and user odbc.ini files.

It looks as if the description was actually the name of the driver not the actual description of the data source.

The sources array will be cleared before new data sources are read.

Parameters:
[in] type The type of source to return
[out] sources The vector of sources
Bug:
At this time you cannot distinguish between user and server data sources.

Definition at line 169 of file environment.cpp.

References odbcpp::handle::check(), DATA_SOURCE_TYPE_SYSTEM, DATA_SOURCE_TYPE_USER, odbcpp::environment::data_source_t::f_description, odbcpp::handle::f_handle, and odbcpp::environment::data_source_t::f_server.

void odbcpp::environment::rollback (  ) 

Immediately rollback all the transactions.

This function sends a rollback to all the transactions of all the connections present in this environment.

If there are no connections, nothing happens.

Exceptions:
odbcpp_error And odbcpp_error will be thrown if the SQL function returns an error.

Definition at line 240 of file environment.cpp.

References odbcpp::handle::check(), odbcpp::handle::f_handle, and odbcpp::handle::f_handle_type.

void odbcpp::environment::set_attr ( SQLINTEGER  attr,
SQLPOINTER  ptr,
SQLINTEGER  length 
)

Set a pointer environment attribute.

This function sets an environment attribute in this environment.

Parameters:
[in] attr The environment attribute to set
[in] ptr The pointer to the data to set
[in] length The size of the data being passed to the environment
Exceptions:
odbcpp_error And odbcpp_error will be thrown if the SQL function returns an error.

Definition at line 143 of file environment.cpp.

References odbcpp::handle::check(), and odbcpp::handle::f_handle.

void odbcpp::environment::set_attr ( SQLINTEGER  attr,
SQLINTEGER  integer 
)

Set an integer environment attribute.

This function sets an environment attribute in this environment.

Parameters:
[in] attr The environment attribute to set
[in] integer The integer to set in this environment
Exceptions:
odbcpp_error And odbcpp_error will be thrown if the SQL function returns an error.

Definition at line 125 of file environment.cpp.

References odbcpp::handle::check(), odbcpp::handle::f_handle, and odbcpp::int_to_ptr().

Referenced by environment().


The documentation for this class was generated from the following files:
Generated on Mon Sep 19 12:52:27 2011 for odbcpp by  doxygen 1.6.3