// *****************************************************************************
// *                                                                           *
// * Function: PrivMgrMDTable::selectCountWhere                                *
// *                                                                           *
// *                                                                           *
// *    This method returns the number of rows in table that match the         *
// * criteria in a WHERE clause.                                               *
// *                                                                           *
// *****************************************************************************
// *                                                                           *
// *  Parameters:                                                              *
// *                                                                           *
// *  <whereClause>                  const std::string &              In       *
// *    is the WHERE clause (including the keyword WHERE).                     *
// *                                                                           *
// *  <whereClause>                  int64_t &                        Out      *
// *    passes back the number of rows read.                                   *
// *                                                                           *
// *****************************************************************************
// *                                                                           *
// * Returns: PrivStatus                                                       *
// *                                                                           *
// *  STATUS_GOOD: Statement executed successfully, valid row count returned.  *
// * STATUS_ERROR: Execution failed. A CLI error is put into the diags area.   *
// *                                                                           *
// *****************************************************************************
PrivStatus PrivMgrMDTable::selectCountWhere(
   const std::string & whereClause,
   int64_t & rowCount)
   
{

   rowCount = 0;

std::string selectStmt ("SELECT COUNT(*) FROM  ");

   selectStmt += tableName_;
   selectStmt += " ";
   selectStmt += whereClause;

int32_t length = 0;
ExeCliInterface cliInterface(STMTHEAP, NULL, NULL, 
  CmpCommon::context()->sqlSession()->getParentQid());

int32_t cliRC = cliInterface.executeImmediate(selectStmt.c_str(),
                                              (char*)&rowCount, 
                                              &length,NULL);

   if (cliRC < 0)
   {
      cliInterface.retrieveSQLDiagnostics(CmpCommon::diags());
      return STATUS_ERROR;
   }
   
   return STATUS_GOOD;
   
}
Ejemplo n.º 2
0
int main()
{
    //insertDB();
    //insertStmt();

    //delDB();
    //insertStmt_bind_null();
    //insertStmt_bind();
    //selectDB();

    //updateStmtBind();

    selectStmt();
    return 0;
}