CDBExecutor Class Reference

The class provides the base interactions with Postgres DB, designed using Singleton Design Pattern. More...

#include <CDBExecutor.h>

List of all members.

Public Member Functions

 CDBExecutor (ConnectionManager *connMan, WinLogger *logger)
 Constructor.
std::string prepareAutoNameSQL (const std::string &sqlCmd)
 Creates a prepared command for later execution.
void prepareSQL (const std::string &sqlCmd, const std::string &stmtName)
 Creates a prepared command for later execution.
void execSQL (const std::string &cmd, int format=1)
 Executes SQL command.
void execPreparedSQL (const std::string &stmtName, int format=1)
 Executes SQL command.
template<class T>
void execPreparedSQLGet (T &tbl, const std::string &stmtName, int format=1)
 Executes prepared SQL command, storing result data into a table container.
template<class T>
void execPreparedSQLSet (T &tbl, const std::string &stmtName, int format=1)
 Executes prepared SQL command, using data from a table container.
void deallocPreparedSQL (const std::string &stmtName)
 Deallocates prepared SQL command.
template<class T>
void execSQLSet (T &tbl, const std::string &SQLCmd, int format=1)
 Executes SQL command, using data from a table container.
template<class T>
void execSQLGet (T &tbl, const std::string &SQLCmd, int format=1)
 Executes SQL command, storing result data into a table container.
template<typename MLtPred, typename SLtPred, typename MSLtGtEqPred, typename Cnt, typename T, typename S>
void linkRows (T &tobj, S &dobj, Cnt &cnt)
 Links a table container to another table container.
template<size_t C1, typename T>
void sortRows (T &tobj, SortOrderType stype=SORTORDER_ASC)
 Sort a table container for given columns.
template<class T>
void addParam (const char *paramType, multi_array< T > &in_array)
 Adding a parameter to the CDBExecutor which will be applied to SQL query.
void setErrorHandler (SmartDBErrHandlerFunc func)
 Sets error handler function.
void setCustomNoticeReceiver (const UsrNoticeReceiver proc) const
 NOTICE handler function.
void clearNoticeReceiver (void) const
 Function for removing custom NOTICE handler set before.

Protected Member Functions

int getRowsCount (PGresult *&result) const
 Gets number of selected rows.


Detailed Description

The class provides the base interactions with Postgres DB, designed using Singleton Design Pattern.

The base purpose of the class is to provide a complete set of functions for interaction with Postgres DB.


Constructor & Destructor Documentation

CDBExecutor::CDBExecutor ( ConnectionManager connMan,
WinLogger *  logger 
)

Constructor.

Parameters:
connMan pointer to a connection manager


Member Function Documentation

std::string CDBExecutor::prepareAutoNameSQL ( const std::string &  sqlCmd  ) 

Creates a prepared command for later execution.

Parameters:
sqlCmd SQL command
Returns:
generated statement name

void CDBExecutor::prepareSQL ( const std::string &  sqlCmd,
const std::string &  stmtName 
)

Creates a prepared command for later execution.

The function creates prepared named statement.Any pre-prepared named command from the current session with the same name is automatically replaced.

Parameters:
sqlCmd SQL command
stmtName name of the prepared SQL command Example:
 prepareSQL("SELECT * FORM tbl", "select12"); 

void CDBExecutor::execSQL ( const std::string &  cmd,
int  format = 1 
)

Executes SQL command.

Parameters:
cmd SQL command
format desired format: '0' - text, '1' - binary

void CDBExecutor::execPreparedSQL ( const std::string &  stmtName,
int  format = 1 
)

Executes SQL command.

The only difference between this function and execPreparedSQL(int) is that this function expects a statement name stmtName

Parameters:
stmtName name of the prepared SQL command
Remarks:
if the connection was lost all prepared SQl commands are lost

template<class T>
void CDBExecutor::execPreparedSQLGet ( T &  tbl,
const std::string &  stmtName,
int  format = 1 
) [inline]

Executes prepared SQL command, storing result data into a table container.

Parameters:
table table container
stmtName name of the prepared SQL command
format desired format: '0' - text, '1' - binary
Remarks:
if the connection was lost all prepared SQl commands are lost Example:
        dbexec->execPreparedSQLGetLast(tbInst);

template<class T>
void CDBExecutor::execPreparedSQLSet ( T &  tbl,
const std::string &  stmtName,
int  format = 1 
) [inline]

Executes prepared SQL command, using data from a table container.

Number of the parameters in prepared SQL command must be the same with number of table container's columns, if it is different an exception will throw. If some parameters was added by addParam and not eat used by execPreparedSQL or execSQL commands an exception will throw too, use clearParams() in this case.

Parameters:
table table container
format desired format: '0' - text, '1' - binary
stmtName name of the prepared SQL command
Remarks:
if the connection was lost all prepared SQl commands are lost Example:
        dbexec->execPreparedSQLSet(tbInst, "select12");

void CDBExecutor::deallocPreparedSQL ( const std::string &  stmtName  ) 

Deallocates prepared SQL command.

Parameters:
stmtName name of the prepared SQL command
Remarks:
if the connection was lost all prepared SQl commands are lost

template<class T>
void CDBExecutor::execSQLSet ( T &  tbl,
const std::string &  SQLCmd,
int  format = 1 
) [inline]

Executes SQL command, using data from a table container.

Number of the parameters in SQL command must be the same with number of table container's columns, if it is different an exception will throw. If some parameters was added by addParam and not eat used by execPreparedSQL or execSQL commands an exception will throw too, use clearParams() in this case.

Parameters:
table table container
format desired format: '0' - text, '1' - binary
Remarks:
if the connection was lost all prepared SQl commands are lost Example:
        dbexec->execSQLSet(tbInst, "select12");

template<class T>
void CDBExecutor::execSQLGet ( T &  tbl,
const std::string &  SQLCmd,
int  format = 1 
) [inline]

Executes SQL command, storing result data into a table container.

Parameters:
table table container
format desired format: '0' - text, '1' - binary
Remarks:
Example:
        dbexec->execSQLGet(tbInst);

template<typename MLtPred, typename SLtPred, typename MSLtGtEqPred, typename ExtenralCnt, typename T, typename S>
void CDBExecutor::linkRows ( T &  tobj,
S &  dobj,
ExtenralCnt &  cnt 
) [inline]

Links a table container to another table container.

Parameters:
tobj table container link to
dobj table to be linked

template<size_t C1, typename T>
void CDBExecutor::sortRows ( T &  tobj,
SortOrderType  stype = SORTORDER_ASC 
) [inline]

Sort a table container for given columns.

Parameters:
tobj table container to be sorted Example:
 dbExecutor->sortRows<1>(*master_table, CDBExecutor::SORTORDER_DESC); //sorting by 2nd column

template<class T>
void CDBExecutor::addParam ( const char *  paramType,
multi_array< T > &  in_array 
) [inline]

Adding a parameter to the CDBExecutor which will be applied to SQL query.

Parameters:
paramType type of the parameter Currently supported parameters: PG_INT8 PG_INT4 PG_INT2 PG_FLOAT8 PG_FLOAT4 PG_VARCHAR PG_TIMESTAMP PG_MAC_ADDR PG_INET PG_DATE PG_BOOL_ARR PG_INT2_ARR PG_INT4_ARR PG_INT8_ARR PG_FLOAT4_ARR PG_FLOAT8_ARR PG_VARCHAR_ARR PG_DATE_ARR PG_TIMESTAMP_ARR PG_MAC_ADDR_ARR PG_INET_ARR PG_BOOL_VEC PG_INT2_VEC PG_INT4_VEC PG_INT8_VEC PG_FLOAT4_VEC PG_FLOAT8_VEC PG_VARCHAR_VEC PG_DATE_VEC PG_TIMESTAMP_VEC PG_MAC_ADDR_VEC PG_INET_VEC
value value of the added parameter
See also:
addParamTimeStamp() Example:
 addParam(PG_INT4, 2); 

void CDBExecutor::setErrorHandler ( SmartDBErrHandlerFunc  func  )  [inline]

Sets error handler function.

Parameters:
func pointer to callback function to disable error handler function set it to NULL Example:
 setErrorHandler(&sqlErrorLogger);
 //smardb calls
 setErrorHandler(NULL);

void CDBExecutor::setCustomNoticeReceiver ( const UsrNoticeReceiver  proc  )  const

NOTICE handler function.

The main purpose of the function is to redefine standard behavior of NOTICE.

Parameters:
proc pointer of user defined function Example:
 struct A
 {
        static void myNoticeReceiver(const char *msg)
        {
                std::cout << "The message is: " << msg << std::endl;
        }
 };
 dbExec->setCustomNoticeReceiver(&A::myNoticeReceiver);

void CDBExecutor::clearNoticeReceiver ( void   )  const

Function for removing custom NOTICE handler set before.

Example:

 dbExec->clearNoticeReceiver();

int CDBExecutor::getRowsCount ( PGresult *&  result  )  const [protected]

Gets number of selected rows.

Parameters:
result query result
Returns:
number of selected rows
Remarks:


The documentation for this class was generated from the following files:

Generated on Wed Jun 3 19:06:55 2009 for SmartDB Framework by  doxygen 1.5.6