#include <CDBExecutor.h>
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. |
The base purpose of the class is to provide a complete set of functions for interaction with Postgres DB.
CDBExecutor::CDBExecutor | ( | ConnectionManager * | connMan, | |
WinLogger * | logger | |||
) |
Constructor.
connMan | pointer to a connection manager |
std::string CDBExecutor::prepareAutoNameSQL | ( | const std::string & | sqlCmd | ) |
Creates a prepared command for later execution.
sqlCmd | SQL command |
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.
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.
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
stmtName | name of the prepared SQL command |
void CDBExecutor::execPreparedSQLGet | ( | T & | tbl, | |
const std::string & | stmtName, | |||
int | format = 1 | |||
) | [inline] |
Executes prepared SQL command, storing result data into a table container.
table | table container | |
stmtName | name of the prepared SQL command | |
format | desired format: '0' - text, '1' - binary |
dbexec->execPreparedSQLGetLast(tbInst);
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.
table | table container | |
format | desired format: '0' - text, '1' - binary | |
stmtName | name of the prepared SQL command |
dbexec->execPreparedSQLSet(tbInst, "select12");
void CDBExecutor::deallocPreparedSQL | ( | const std::string & | stmtName | ) |
Deallocates prepared SQL command.
stmtName | name of the prepared SQL command |
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.
table | table container | |
format | desired format: '0' - text, '1' - binary |
dbexec->execSQLSet(tbInst, "select12");
void CDBExecutor::execSQLGet | ( | T & | tbl, | |
const std::string & | SQLCmd, | |||
int | format = 1 | |||
) | [inline] |
Executes SQL command, storing result data into a table container.
table | table container | |
format | desired format: '0' - text, '1' - binary |
dbexec->execSQLGet(tbInst);
void CDBExecutor::linkRows | ( | T & | tobj, | |
S & | dobj, | |||
ExtenralCnt & | cnt | |||
) | [inline] |
Links a table container to another table container.
tobj | table container link to | |
dobj | table to be linked |
void CDBExecutor::sortRows | ( | T & | tobj, | |
SortOrderType | stype = SORTORDER_ASC | |||
) | [inline] |
Sort a table container for given columns.
tobj | table container to be sorted Example: dbExecutor->sortRows<1>(*master_table, CDBExecutor::SORTORDER_DESC); //sorting by 2nd column
|
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.
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 |
addParam(PG_INT4, 2);
void CDBExecutor::setErrorHandler | ( | SmartDBErrHandlerFunc | func | ) | [inline] |
Sets error handler function.
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.
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.
result | query result |