Safir SDK Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Safir::Databases::Odbc::Statement Class Reference

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>

Inheritance diagram for Safir::Databases::Odbc::Statement:
Collaboration diagram for Safir::Databases::Odbc::Statement:

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 > &param)
 Binds a parameter to a statement. More...
 
template<short sSqlType, short sInputOutputType>
void BindParameter (unsigned short usParameterNumber, Internal::NonBufferedWideStringParameter< sSqlType, sInputOutputType > &param)
 
template<short sCType, short sSqlType, class Type , short sInputOutputType, unsigned long lColumnSize>
void BindLongParameter (unsigned short usParameterNumber, Internal::Parameter< sCType, sSqlType, Type, sInputOutputType, lColumnSize > &param)
 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 > &param)
 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
 

Detailed Description

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.

Constructor & Destructor Documentation

Safir::Databases::Odbc::Statement::Statement ( )

Constructor.

Safir::Databases::Odbc::Statement::~Statement ( )

Destructor.

Member Function Documentation

void Safir::Databases::Odbc::Statement::Alloc ( Connection pConnection)

Allocates a new statement in a connection.

See SQLAllocHandle in ODBC documentation for more info.

Parameters
[in]pConnection- the connection the statement is made through.
Exceptions
ReconnectException- SQLAllocHandle failed. Check GetDiagRec for info.
template<short sValueType, class Type >
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.

Parameters
[in]usColumnNumber- the position of this column as returned by the query. Starts at 1.
[in]column- an instance of the column class.
Exceptions
ReconnectException- The operation cannot succeed without reconnecting to the RDBMS
RetryException- Retry the operation.

References __WFILE__, and IsValid().

Here is the call graph for this function:

template<short sCType, short sSqlType, class Type , short sInputOutputType, unsigned long lColumnSize>
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.

Parameters
[in]usParameterNumber- the position of this parameter in the parameter list. Starts at 1.
[in]param- an instance of the parameter class.
Exceptions
ReconnectException- The operation cannot succeed without reconnecting to the RDBMS
RetryException- Retry the operation.

References __WFILE__, and IsValid().

Here is the call graph for this function:

template<short sCType, short sSqlType, class Type , short sInputOutputType, unsigned long lColumnSize>
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.

Parameters
[in]usParameterNumber- the position of this parameter in the parameter list. Starts at 1.
[in]param- an instance of the parameter class.
Exceptions
ReconnectException- The operation cannot succeed without reconnecting to the RDBMS
RetryException- Retry the operation.

References __WFILE__, and IsValid().

Here is the call graph for this function:

template<short sSqlType, short sInputOutputType>
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.

Exceptions
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.

Parameters
[in]wszSqlCommand- the sql query this statement shall execute.
Exceptions
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.

Exceptions
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.

Returns
True if data was returned. False if at end of the recordset.
Exceptions
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.

Exceptions
ReconnectException- SQLFreeHandle failed. Check GetDiagRec for info.
template<short sValueType, class Type >
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.

Parameters
[in]usColumnNumber- the position of this column as returned by the query. Starts at 1.
[in]column- an instance of the column class.
Returns
True if data was returned. False if at end of the recordset.
Exceptions
ReconnectException- The operation cannot succeed without reconnecting to the RDBMS
RetryException- Retry the operation.

References __WFILE__, and IsValid().

Here is the call graph for this function:

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.

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.
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.

Returns
Returns the number of columns generated by last statement. Returns 0 if no columns were generated.
Exceptions
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.

Parameters
[in]lAttribute- An integer representing the attribute
[out]lValue- The value of the attribute
Exceptions
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.

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
ReconnectException- SQLGetStmtAttr failed. Check GetDiagRec for info.
SQLHDBC Safir::Databases::Odbc::Statement::Handle ( ) const

Returns the ODBC Handle of the statement.

Returns
An ODBC statement handle.
bool Safir::Databases::Odbc::Statement::IsValid ( ) const

Checks if this statement is a valid allocated statement.

Returns
True if the statement is ok to use.

Referenced by BindColumn(), BindLongParameter(), BindParameter(), GetData(), and PutData().

Here is the caller graph for this function:

bool Safir::Databases::Odbc::Statement::MoreResults ( )

Retrieves more results (resultsets or parameters) from the database.

See SQLMoreResults in ODBC documentation for more info.

Returns
True if more result sets exists. False if all result sets have been processed.
Exceptions
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.

Parameters
[out]lParameter- The next parameter that need data.
Returns
True if more parameters needed data otherwise False;
Exceptions
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.

Parameters
[in]wszSqlCommand- the sql query this statement shall execute.
Exceptions
ReconnectException- SQLPrepare failed. Check GetDiagRec for info.
RetryException- Retry the operation.
template<short sCType, short sSqlType, class Type , short sInputOutputType, unsigned long lColumnSize>
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.

Parameters
[in]param- an instance of the parameter class.
Exceptions
ReconnectException- The operation cannot succeed without reconnecting to the RDBMS
RetryException- Retry the operation.

References __WFILE__, and IsValid().

Here is the call graph for this function:

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.

Parameters
[in]lAttribute- An integer representing the attribute
[in]lValue- The value of the attribute to be set
Exceptions
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.

Parameters
[in]lAttribute- An integer representing the attribute
[in]wszValue- The value of the attribute to be set
Exceptions
ReconnectException- SQLSetStmtAttr failed. Check GetDiagRec for info.

Friends And Related Function Documentation