Safir SDK Core
|
The Connection class models a connection made to the database engine. More...
#include <Safir/Databases/Odbc/Connection.h>
Public Member Functions | |
Connection () | |
Constructor. More... | |
~Connection () | |
Destructor. More... | |
void | Alloc (const Environment &environment) |
Allocates a new connection to the database. More... | |
void | Free () |
Frees the connection previously allocated to the database. More... | |
void | Connect (const std::wstring &wszConnectionString) |
establishes a connection to the database. More... | |
void | Connect (char *cszConnectionString) |
establishes a connection to the database. More... | |
void | Disconnect () |
disconnects from the database. More... | |
void | UseAutoTransactions () |
Set odbc to automatically commit each transaction after a successful query. More... | |
void | UseManualTransactions () |
Set odbc to require manual commits to end transactions. More... | |
void | Commit () |
Commits the changes permanently made in this transaction. More... | |
void | Rollback () |
Remove all changes made in this transaction. More... | |
void | SetConnectAttr (long lAttribute, long lValue) |
Sets a value for a ODBC connection attribute. More... | |
void | SetConnectAttr (long lAttribute, const std::wstring &wszValue) |
Sets a value for a ODBC connection attribute. More... | |
void | GetConnectAttr (long lAttribute, long &lValue) const |
Gets a value for a ODBC connection attribute. More... | |
void | GetConnectAttr (long lAttribute, wchar_t *wszValue, unsigned long ulLength) const |
Gets a value for a ODBC connection attribute. More... | |
bool | GetDiagRec (short sRecNumber, std::wstring &SqlState, boost::int32_t &NativeError, std::wstring &MessageText, bool &bDataRead) const |
Get a diagnostics record. More... | |
bool | IsValid () const |
Checks if this connection is a valid allocated connection. More... | |
bool | IsConnected () const |
Checks if a connection has been established. More... | |
SQLHDBC | Handle () const |
Returns the ODBC Handle of the environment. More... | |
Friends | |
class | Safir::Databases::Odbc::Statement |
The Connection class models a connection made to the database engine.
An application should have one connection object per connection and in ODBC one connection can only process one statement at the time. All Connections needs to be allocated and deallocated before use.
Safir::Databases::Odbc::Connection::Connection | ( | ) |
Constructor.
Safir::Databases::Odbc::Connection::~Connection | ( | ) |
Destructor.
void Safir::Databases::Odbc::Connection::Alloc | ( | const Environment & | environment | ) |
Allocates a new connection to the database.
See SQLAllocHandle in ODBC documentation for more info.
[in] | environment | - the environment the connection is made through. |
ReconnectException | - SQLAllocHandle failed. Check GetDiagRec for info. |
void Safir::Databases::Odbc::Connection::Commit | ( | ) |
Commits the changes permanently made in this transaction.
Call UseManualTransactions() to be able to use Commit() and Rollback() to end transactions. See SQLSetConnectAttr and the attribute SQL_ATTR_AUTOCOMMIT in ODBC documentation for more info.
ReconnectException | - SQLEndTran failed. Check GetDiagRec for info. |
void Safir::Databases::Odbc::Connection::Connect | ( | const std::wstring & | wszConnectionString | ) |
establishes a connection to the database.
See SQLDriverConnect in ODBC documentation for more info.
[in] | wszConnectionString | - an odbc connection string in which attributes for the connection to the RDBMS is contained. |
ReconnectException | - SQLDriverConnect failed. Check GetDiagRec for info. |
void Safir::Databases::Odbc::Connection::Connect | ( | char * | cszConnectionString | ) |
establishes a connection to the database.
See SQLDriverConnect in ODBC documentation for more info.
[in] | cszConnectionString | - an odbc connection string in which attributes for the connection to the RDBMS is contained. |
ReconnectException | - SQLDriverConnect failed. Check GetDiagRec for info. |
void Safir::Databases::Odbc::Connection::Disconnect | ( | ) |
disconnects from the database.
All statements are automatically freed by ODBC when disconnecting. After a disconnect statements have to be reallocated and prepared. Columns and parameters have to be rebound.
See SQLDisconnect in ODBC documentation for more info.
TimeoutException | - Timeout has occurred. |
void Safir::Databases::Odbc::Connection::Free | ( | ) |
Frees the connection previously allocated to the database.
See SQLFreeHandle in ODBC documentation for more info.
void Safir::Databases::Odbc::Connection::GetConnectAttr | ( | long | lAttribute, |
long & | lValue | ||
) | const |
Gets a value for a ODBC connection attribute.
See SQLSetConnectAttr in ODBC documentation for more info.
[in] | lAttribute | - An integer representing the attribute |
[out] | lValue | - The value of the attribute |
ReconnectException | - SQLGetConnectAttr failed. Check GetDiagRec for info. |
void Safir::Databases::Odbc::Connection::GetConnectAttr | ( | long | lAttribute, |
wchar_t * | wszValue, | ||
unsigned long | ulLength | ||
) | const |
Gets a value for a ODBC connection attribute.
See SQLSetConnectAttr in ODBC documentation for more info.
[in] | lAttribute | - An integer representing the attribute |
[out] | wszValue | - The value of the attribute |
[in] | ulLength | - Size in bytes of the szValue buffer. |
ReconnectException | - SQLGetConnectAttr failed. Check GetDiagRec for info. |
bool Safir::Databases::Odbc::Connection::GetDiagRec | ( | short | sRecNumber, |
std::wstring & | SqlState, | ||
boost::int32_t & | NativeError, | ||
std::wstring & | MessageText, | ||
bool & | bDataRead | ||
) | const |
Get a diagnostics record.
See SQLGetDiagRec in ODBC documentation for more info.
[in] | sRecNumber | - The sql error record. Starts at 1. |
[out] | SqlState | - The five char sql state error code. |
[out] | NativeError | - Driver specific error code. |
[out] | MessageText | - The diagnostic message text string. |
[out] | bDataRead | - true if data has been placed in the buffers. |
SQLHDBC Safir::Databases::Odbc::Connection::Handle | ( | ) | const |
Returns the ODBC Handle of the environment.
bool Safir::Databases::Odbc::Connection::IsConnected | ( | ) | const |
Checks if a connection has been established.
bool Safir::Databases::Odbc::Connection::IsValid | ( | ) | const |
Checks if this connection is a valid allocated connection.
void Safir::Databases::Odbc::Connection::Rollback | ( | ) |
Remove all changes made in this transaction.
Call UseManualTransactions() to be able to use Commit() and Rollback() to end transactions. See SQLSetConnectAttr and the attribute SQL_ATTR_AUTOCOMMIT in ODBC documentation for more info.
ReconnectException | - SQLEndTran failed. Check GetDiagRec for info. |
void Safir::Databases::Odbc::Connection::SetConnectAttr | ( | long | lAttribute, |
long | lValue | ||
) |
Sets a value for a ODBC connection attribute.
See SQLSetConnectAttr in ODBC documentation for more info.
[in] | lAttribute | - An integer representing the attribute |
[in] | lValue | - The value of the attribute to be set |
ReconnectException | - SQLSetConnectAttr failed. Check GetDiagRec for info. |
Referenced by UseAutoTransactions(), and UseManualTransactions().
void Safir::Databases::Odbc::Connection::SetConnectAttr | ( | long | lAttribute, |
const std::wstring & | wszValue | ||
) |
Sets a value for a ODBC connection attribute.
See SQLSetConnectAttr in ODBC documentation for more info.
[in] | lAttribute | - An integer representing the attribute |
[in] | wszValue | - The value of the attribute to be set |
ReconnectException | - SQLSetConnectAttr failed. Check GetDiagRec for info. |
void Safir::Databases::Odbc::Connection::UseAutoTransactions | ( | ) |
Set odbc to automatically commit each transaction after a successful query.
This is the default choice. See SQLSetConnectAttr and the attribute SQL_ATTR_AUTOCOMMIT in ODBC documentation for more info.
ReconnectException | - SQLSetConnectAttr failed. Check GetDiagRec for info. |
References SetConnectAttr().
void Safir::Databases::Odbc::Connection::UseManualTransactions | ( | ) |
Set odbc to require manual commits to end transactions.
Call this to be able to use Commit() and Rollback() to end transactions. See SQLSetConnectAttr and the attribute SQL_ATTR_AUTOCOMMIT in ODBC documentation for more info.
ReconnectException | - SQLSetConnectAttr failed. Check GetDiagRec for info. |
References SetConnectAttr().
|
friend |