Safir SDK Core
|
The Statement class models a statement made to the database engine and one statement object should be made for each statement or query to the database. More...
#include <Safir/Databases/Odbc/Statement.h>
Public Member Functions | |
Statement () | |
Constructor. More... | |
~Statement () | |
Destructor. More... | |
void | Alloc (Connection &pConnection) |
Allocates a new statement in a connection. More... | |
void | Free () |
Frees the statement previously allocated to the database. More... | |
void | CloseCursor () |
Closes a recordset returned by an Execute() or ExecDirect(). More... | |
void | Execute () |
Executes an already prepared statement. More... | |
void | Prepare (const std::wstring &wszSqlCommand) |
Prepares a statement for later execution. More... | |
void | ExecDirect (const std::wstring &wszSqlCommand) |
Prepares and executes an statement. More... | |
bool | Fetch () |
Reads one row in an recordset into the columns bound to this query. More... | |
bool | MoreResults () |
Retrieves more results (resultsets or parameters) from the database. More... | |
int | GetNumberOfColumns () const |
Returns the number of columns generated from a query. More... | |
void | SetStmtAttr (long lAttribute, long lValue) |
Sets a value for a ODBC statement attribute. More... | |
void | SetStmtAttr (long lAttribute, const std::wstring &wszValue) |
Sets a value for a ODBC statement attribute. More... | |
void | GetStmtAttr (long lAttribute, long &lValue) const |
Gets a value for a ODBC statement attribute. More... | |
void | GetStmtAttr (long lAttribute, wchar_t *wszValue, unsigned long ulLength) const |
Gets a value for a ODBC statement attribute. More... | |
bool | ParamData (unsigned short &lParameter) const |
Changes PutData() to add data to next parameter. More... | |
template<short sCType, short sSqlType, class Type , short sInputOutputType, unsigned long lColumnSize> | |
void | BindParameter (unsigned short usParameterNumber, Internal::Parameter< sCType, sSqlType, Type, sInputOutputType, lColumnSize > ¶m) |
Binds a parameter to a statement. More... | |
template<short sSqlType, short sInputOutputType> | |
void | BindParameter (unsigned short usParameterNumber, Internal::NonBufferedWideStringParameter< sSqlType, sInputOutputType > ¶m) |
template<short sCType, short sSqlType, class Type , short sInputOutputType, unsigned long lColumnSize> | |
void | BindLongParameter (unsigned short usParameterNumber, Internal::Parameter< sCType, sSqlType, Type, sInputOutputType, lColumnSize > ¶m) |
Binds a long parameter to a statement. More... | |
template<short sValueType, class Type > | |
void | BindColumn (unsigned short usColumnNumber, Internal::Column< sValueType, Type > &column) |
Binds a column to a statement. More... | |
template<short sValueType, class Type > | |
bool | GetData (unsigned short usColumnNumber, Internal::Column< sValueType, Type > &column) |
Get data from a column. More... | |
template<short sCType, short sSqlType, class Type , short sInputOutputType, unsigned long lColumnSize> | |
void | PutData (Internal::Parameter< sCType, sSqlType, Type, sInputOutputType, lColumnSize > ¶m) |
Put data into a parameter. 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 statement is a valid allocated statement. More... | |
SQLHDBC | Handle () const |
Returns the ODBC Handle of the statement. More... | |
Friends | |
class | Safir::Databases::Odbc::Connection |
The Statement class models a statement made to the database engine and one statement object should be made for each statement or query to the database.
All statements needs to be Allocated and Deallocated at connect and disconnect.
Safir::Databases::Odbc::Statement::Statement | ( | ) |
Constructor.
Safir::Databases::Odbc::Statement::~Statement | ( | ) |
Destructor.
void Safir::Databases::Odbc::Statement::Alloc | ( | Connection & | pConnection | ) |
Allocates a new statement in a connection.
See SQLAllocHandle in ODBC documentation for more info.
[in] | pConnection | - the connection the statement is made through. |
ReconnectException | - SQLAllocHandle failed. Check GetDiagRec for info. |
void Safir::Databases::Odbc::Statement::BindColumn | ( | unsigned short | usColumnNumber, |
Internal::Column< sValueType, Type > & | column | ||
) |
Binds a column to a statement.
Columns are unbound when connection is disconnected. See SQLBindColumn in ODBC documentation for more info.
[in] | usColumnNumber | - the position of this column as returned by the query. Starts at 1. |
[in] | column | - an instance of the column class. |
ReconnectException | - The operation cannot succeed without reconnecting to the RDBMS |
RetryException | - Retry the operation. |
References __WFILE__, and IsValid().
void Safir::Databases::Odbc::Statement::BindLongParameter | ( | unsigned short | usParameterNumber, |
Internal::Parameter< sCType, sSqlType, Type, sInputOutputType, lColumnSize > & | param | ||
) |
Binds a long parameter to a statement.
Parameters are unbound when connection is disconnected. See SQLBindParameter in ODBC documentation for more info.
[in] | usParameterNumber | - the position of this parameter in the parameter list. Starts at 1. |
[in] | param | - an instance of the parameter class. |
ReconnectException | - The operation cannot succeed without reconnecting to the RDBMS |
RetryException | - Retry the operation. |
References __WFILE__, and IsValid().
void Safir::Databases::Odbc::Statement::BindParameter | ( | unsigned short | usParameterNumber, |
Internal::Parameter< sCType, sSqlType, Type, sInputOutputType, lColumnSize > & | param | ||
) |
Binds a parameter to a statement.
Parameters are unbound when connection is disconnected. See SQLBindParameter in ODBC documentation for more info.
[in] | usParameterNumber | - the position of this parameter in the parameter list. Starts at 1. |
[in] | param | - an instance of the parameter class. |
ReconnectException | - The operation cannot succeed without reconnecting to the RDBMS |
RetryException | - Retry the operation. |
References __WFILE__, and IsValid().
void Safir::Databases::Odbc::Statement::BindParameter | ( | unsigned short | usParameterNumber, |
Internal::NonBufferedWideStringParameter< sSqlType, sInputOutputType > & | param | ||
) |
References __WFILE__.
void Safir::Databases::Odbc::Statement::CloseCursor | ( | ) |
Closes a recordset returned by an Execute() or ExecDirect().
See SQLCloseCursor in ODBC documentation for more info.
ReconnectException | - SQLCloseCursor failed. Check GetDiagRec for info. |
void Safir::Databases::Odbc::Statement::ExecDirect | ( | const std::wstring & | wszSqlCommand | ) |
Prepares and executes an statement.
See SQLExecDirect in ODBC documentation for more info.
[in] | wszSqlCommand | - the sql query this statement shall execute. |
ReconnectException | - SQLExecDirect failed. Check GetDiagRec for info. |
RetryException | - Retry the operation. |
TimeoutException | - Timeout has occurred. Retry the operation. |
void Safir::Databases::Odbc::Statement::Execute | ( | ) |
Executes an already prepared statement.
See SQLExecute in ODBC documentation for more info.
IntegrityConstraintException | - The query violated the integrity constraints of the database. |
ReconnectException | - SQLExecute failed. Check GetDiagRec for info. |
RetryException | - Retry the operation. |
TimeoutException | - Timeout has occurred. Retry the operation. |
bool Safir::Databases::Odbc::Statement::Fetch | ( | ) |
Reads one row in an recordset into the columns bound to this query.
See SQLFetch in ODBC documentation for more info.
ReconnectException | - SQLFetch failed. Check GetDiagRec for info. |
RetryException | - Retry the operation. |
TimeoutException | - Timeout has occurred. Retry the operation. |
void Safir::Databases::Odbc::Statement::Free | ( | ) |
Frees the statement previously allocated to the database.
Statements are freed automatically when disconnected. See SQLFreeHandle in ODBC documentation for more info.
ReconnectException | - SQLFreeHandle failed. Check GetDiagRec for info. |
bool Safir::Databases::Odbc::Statement::GetData | ( | unsigned short | usColumnNumber, |
Internal::Column< sValueType, Type > & | column | ||
) |
Get data from a column.
See SQLGetData in ODBC documentation for more info.
[in] | usColumnNumber | - the position of this column as returned by the query. Starts at 1. |
[in] | column | - an instance of the column class. |
ReconnectException | - The operation cannot succeed without reconnecting to the RDBMS |
RetryException | - Retry the operation. |
References __WFILE__, and IsValid().
bool Safir::Databases::Odbc::Statement::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. |
int Safir::Databases::Odbc::Statement::GetNumberOfColumns | ( | ) | const |
Returns the number of columns generated from a query.
Call this method after a successful call to execute. See SQLNumResultCols in ODBC documentation for more info.
ReconnectException | - SQLNumResultCols failed. Check GetDiagRec for info. |
void Safir::Databases::Odbc::Statement::GetStmtAttr | ( | long | lAttribute, |
long & | lValue | ||
) | const |
Gets a value for a ODBC statement attribute.
See SQLGetStmtAttr in ODBC documentation for more info.
[in] | lAttribute | - An integer representing the attribute |
[out] | lValue | - The value of the attribute |
ReconnectException | - SQLGetStmtAttr failed. Check GetDiagRec for info. |
void Safir::Databases::Odbc::Statement::GetStmtAttr | ( | long | lAttribute, |
wchar_t * | wszValue, | ||
unsigned long | ulLength | ||
) | const |
Gets a value for a ODBC statement attribute.
See SQLGetStmtAttr 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 | - SQLGetStmtAttr failed. Check GetDiagRec for info. |
SQLHDBC Safir::Databases::Odbc::Statement::Handle | ( | ) | const |
Returns the ODBC Handle of the statement.
bool Safir::Databases::Odbc::Statement::IsValid | ( | ) | const |
Checks if this statement is a valid allocated statement.
Referenced by BindColumn(), BindLongParameter(), BindParameter(), GetData(), and PutData().
bool Safir::Databases::Odbc::Statement::MoreResults | ( | ) |
Retrieves more results (resultsets or parameters) from the database.
See SQLMoreResults in ODBC documentation for more info.
ReconnectException | - SQLMoreResults failed. Check GetDiagRec for info. |
RetryException | - Retry the operation. |
bool Safir::Databases::Odbc::Statement::ParamData | ( | unsigned short & | lParameter | ) | const |
Changes PutData() to add data to next parameter.
See SQLParamData in ODBC documentation for more info.
[out] | lParameter | - The next parameter that need data. |
ReconnectException | - SQLParamData failed. Check GetDiagRec for info. |
RetryException | - Retry the operation. |
void Safir::Databases::Odbc::Statement::Prepare | ( | const std::wstring & | wszSqlCommand | ) |
Prepares a statement for later execution.
See SQLPrepare in ODBC documentation for more info.
[in] | wszSqlCommand | - the sql query this statement shall execute. |
ReconnectException | - SQLPrepare failed. Check GetDiagRec for info. |
RetryException | - Retry the operation. |
void Safir::Databases::Odbc::Statement::PutData | ( | Internal::Parameter< sCType, sSqlType, Type, sInputOutputType, lColumnSize > & | param | ) |
Put data into a parameter.
See SQLPutData in ODBC documentation for more info.
[in] | param | - an instance of the parameter class. |
ReconnectException | - The operation cannot succeed without reconnecting to the RDBMS |
RetryException | - Retry the operation. |
References __WFILE__, and IsValid().
void Safir::Databases::Odbc::Statement::SetStmtAttr | ( | long | lAttribute, |
long | lValue | ||
) |
Sets a value for a ODBC statement attribute.
See SQLSetStmtAttr in ODBC documentation for more info.
[in] | lAttribute | - An integer representing the attribute |
[in] | lValue | - The value of the attribute to be set |
ReconnectException | - SQLSetStmtAttr failed. Check GetDiagRec for info. |
void Safir::Databases::Odbc::Statement::SetStmtAttr | ( | long | lAttribute, |
const std::wstring & | wszValue | ||
) |
Sets a value for a ODBC statement attribute.
See SQLSetStmtAttr in ODBC documentation for more info.
[in] | lAttribute | - An integer representing the attribute |
[in] | wszValue | - The value of the attribute to be set |
ReconnectException | - SQLSetStmtAttr failed. Check GetDiagRec for info. |
|
friend |