The Connection class models a connection made to the database engine.
More...
#include <Safir/Databases/Odbc/Connection.h>
|
| 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...
|
|
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.
- Deprecated:
- All functionality in the Safir::Databases::Odbc namespace is deprecated.
Safir::Databases::Odbc::Connection::Connection |
( |
| ) |
|
Safir::Databases::Odbc::Connection::~Connection |
( |
| ) |
|
void Safir::Databases::Odbc::Connection::Alloc |
( |
const Environment & |
environment | ) |
|
Allocates a new connection to the database.
See SQLAllocHandle in ODBC documentation for more info.
- Parameters
-
[in] | environment | - the environment the connection is made through. |
- Exceptions
-
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.
- Exceptions
-
void Safir::Databases::Odbc::Connection::Connect |
( |
const std::wstring & |
wszConnectionString | ) |
|
establishes a connection to the database.
See SQLDriverConnect in ODBC documentation for more info.
- Parameters
-
[in] | wszConnectionString | - an odbc connection string in which attributes for the connection to the RDBMS is contained. |
- Exceptions
-
void Safir::Databases::Odbc::Connection::Connect |
( |
char * |
cszConnectionString | ) |
|
establishes a connection to the database.
See SQLDriverConnect in ODBC documentation for more info.
- Parameters
-
[in] | cszConnectionString | - an odbc connection string in which attributes for the connection to the RDBMS is contained. |
- Exceptions
-
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.
- Exceptions
-
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.
- Parameters
-
[in] | lAttribute | - An integer representing the attribute |
[out] | lValue | - The value of the attribute |
- Exceptions
-
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.
- Parameters
-
[in] | lAttribute | - An integer representing the attribute |
[out] | wszValue | - The value of the attribute |
[in] | ulLength | - Size in bytes of the szValue buffer. |
- Exceptions
-
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.
- Parameters
-
[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.
- Returns
- An ODBC Environment handle.
bool Safir::Databases::Odbc::Connection::IsConnected |
( |
| ) |
const |
Checks if a connection has been established.
- Returns
- An ODBC Environment handle.
bool Safir::Databases::Odbc::Connection::IsValid |
( |
| ) |
const |
Checks if this connection is a valid allocated connection.
- Returns
- True if the connection is ok to use.
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.
- Exceptions
-
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.
- Parameters
-
[in] | lAttribute | - An integer representing the attribute |
[in] | lValue | - The value of the attribute to be set |
- Exceptions
-
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.
- Parameters
-
[in] | lAttribute | - An integer representing the attribute |
[in] | wszValue | - The value of the attribute to be set |
- Exceptions
-
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.
- Exceptions
-
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.
- Exceptions
-
References SetConnectAttr().