ResultType TrafficCop::ExecuteStatement( const std::string &query, std::vector<StatementResult> &result, std::vector<FieldInfo> &tuple_descriptor, int &rows_changed, std::string &error_message, const size_t thread_id UNUSED_ATTRIBUTE) { LOG_TRACE("Received %s", query.c_str()); // Prepare the statement std::string unnamed_statement = "unnamed"; auto statement = PrepareStatement(unnamed_statement, query, error_message); if (statement.get() == nullptr) { return ResultType::FAILURE; } // Then, execute the statement bool unnamed = true; std::vector<int> result_format(statement->GetTupleDescriptor().size(), 0); std::vector<type::Value> params; auto status = ExecuteStatement(statement, params, unnamed, nullptr, result_format, result, rows_changed, error_message, thread_id); if (status == ResultType::SUCCESS) { LOG_TRACE("Execution succeeded!"); tuple_descriptor = std::move(statement->GetTupleDescriptor()); } else { LOG_TRACE("Execution failed!"); } return status; }
void CRUAuditRefreshTaskExecutor::EpilogueHandleOnStatementMV() { CRUMV &mv = GetRootMV(); CRUTblList &tblList = mv.GetTablesUsedByMe(); DSListPosition pos = tblList.GetHeadPosition(); Int32 i=0; while (NULL != pos) { CRUTbl *pTbl = tblList.GetNext(pos); CDMPreparedStatement *pStat = pLockTablesTEDynamicContainer_->GetPreparedStatement(i); // Perform the LOCK TABLE statement on the used table // (the lock overlaps the original RP open, therefore // guaranteeing the lock continuity). ExecuteStatement(*pStat,IDS_RU_IREFRESH_FAILED); // Release the DDL lock AND the read-protected open on the used table. pTbl->ReleaseResources(); } }
void CRUUnAuditRefreshTaskExecutor::UnLockMV() { CDMPreparedStatement *pStmt = unAuditRefreshTEDynamicContainer_. GetPreparedStatement(RU_UNLOCK_TABLE); ExecuteStatement(*pStmt, IDS_RU_UNLOCK_TABLE_FAILED); }
ExecReturnCodes OPSynWhile :: Execute ( ) { ExecReturnCodes rc = ERC_undefined; BEGINSEQ if ( CheckCO() ) ERROR while ( (rc = ExecuteSource()) == ERC_success ) { if ( !source->GetValue()->IsTrue() ) LEAVESEQ switch ( rc = ExecuteStatement(0) ) { case ERC_terminate : ERROR case ERC_null : case ERC_success : break; case ERC_undefined : // no statements case ERC_continue : rc = ERC_success; break; case ERC_break : rc = ERC_success; default : LEAVESEQ } } RECOVER ResetValue(); rc = ERC_terminate; ENDSEQ if ( rc != ERC_terminate ) RegisterLastValue(); return(rc); }
void CRULogCleanupTaskExecutor::CleanLogFirstN(SQL_STATEMENT statement) { // Compilation Stage CDMPreparedStatement *pStat = logCleanupTEDynamicContainer_.GetPreparedStatement(statement); while (TRUE) { BeginTransaction(); ExecuteStatement(*pStat, IDS_RU_LOG_CLEANUP_FAILED, NULL, /* error argument */ TRUE /* Obtain row count */); CommitTransaction(); TESTPOINT(CRUGlobals::TESTPOINT160); if (pStat->GetRowsAffected() < CRULogCleanupSQLComposer::MAX_ROW_TO_DELETE_IN_SINGLE_TXN) { break; } } }
void CRURefreshTaskExecutor::ApplyUserCQSForInternalRefresh() { CDMPreparedStatement *pStat = pRefreshTEDynamicContainer_-> GetPreparedStatement(USER_CQS_FORCE); ExecuteStatement(*pStat, USER_CQS_FORCE); CRUGlobals::GetInstance()->GetJournal().LogMessage( pRefreshTEDynamicContainer_->GetLastSQL(USER_CQS_FORCE)); }
void CRURefreshTaskExecutor::ResetIRCompilerDefaults() { // LCOV_EXCL_START :rfi if ((FORCE_CQS & forceFlags_) || (FORCE_USER_CQS & forceFlags_)) { CDMPreparedStatement *pStat = pRefreshTEDynamicContainer_-> GetPreparedStatement(CQS_CUT_STAT); ExecuteStatement(*pStat, CQS_CUT_STAT); } if (forceFlags_ & FORCE_MV_MDAM || forceFlags_ & FORCE_TABLE_MDAM) { CDMPreparedStatement *pStat = pRefreshTEDynamicContainer_->GetPreparedStatement(RESET_MDAM_STAT); ExecuteStatement(*pStat,RESET_MDAM_STAT); } // LCOV_EXCL_STOP }
//--------------------------------------------------------------------------// // CRUAuditRefreshTaskExecutor::ExecuteIndexStatmenents() // // Execute all the index related statments in the container //--------------------------------------------------------------------------// void CRUAuditRefreshTaskExecutor::ExecuteIndexStatmenents(CRUSQLDynamicStatementContainer &container, Lng32 errorCode) { short numStmt = container.GetNumOfStmt(); for (short i=0;i<numStmt;i++) { CDMPreparedStatement *pStmt = container.GetPreparedStatement(i); ExecuteStatement(*pStmt, errorCode); } }
void CRULogCleanupTaskExecutor::CleanLogMultiCommit() { // Compilation Stage CDMPreparedStatement *pStat = logCleanupTEDynamicContainer_.GetPreparedStatement(CLEAN_IUD_MCOMMIT); ExecuteStatement(*pStat, IDS_RU_LOG_CLEANUP_FAILED, NULL, /* error argument */ TRUE /* Obtain row count */); TESTPOINT(CRUGlobals::TESTPOINT160); }
void CRURefreshTaskExecutor::ExecuteShowExplain() { if (FALSE == (FORCE_SHOW_EXPLAIN & forceFlags_)) { return; } CDMPreparedStatement *pStat = pRefreshTEDynamicContainer_-> GetPreparedStatement(SHOW_EXPLAIN); ExecuteStatement(*pStat, SHOW_EXPLAIN); CRUGlobals::GetInstance()->GetJournal().LogMessage( pRefreshTEDynamicContainer_->GetLastSQL(SHOW_EXPLAIN)); }
int main(int argc, char * argv[]) { if (2 != argc) { PrintUsage(argv[0]); return 1; } std::ofstream log("mydb.log"); Log::SetStream(LogType::Info, log); Log::SetStream(LogType::Debug, log); Log::SetStream(LogType::Error, log); std::string userInput; InputReader reader(std::cin); CSVPrinter printer(std::cout); Log(LogType::Info) << "Start listening to unput." << std::endl; try { MyDB db(argv[1]); std::cout << "Hello from MyDB!" << std::endl; while (true) { std::cout << "> "; userInput = reader.Read(); try { auto statement = SQLParser::Instance().ParseStatement(userInput); if (!statement) { // input == quit/exit std::cout << "Goodbye!" << std::endl; break; } ExecuteStatement(db, statement, printer); } catch (SQLParserException const & e) { std::cerr << "ERROR: " << e.what() << std::endl; Log(LogType::Error) << "Exception while parsing " << userInput << ": " << e.what() << std::endl; } catch(std::runtime_error const & e) { std::cerr << "ERROR: " << e.what() << std::endl; Log(LogType::Error) << "Exception in main: " << e.what() << std::endl; } } } catch (std::exception const & e) { std::cerr << "FATAL ERROR: " << e.what() << std::endl; Log(LogType::Error) << "std::exception: " << e.what() << std::endl; return 1; } return 0; }
TInt64 CRULogCleanupTaskExecutor::getRowCount() { CDMPreparedStatement *pStat = logCleanupTEDynamicContainer_.GetPreparedStatement(CLEAN_ROWCOUNT); ExecuteStatement(*pStat, IDS_RU_LOG_CLEANUP_FAILED, NULL, /* error argument */ TRUE, /* Obtain row count */ TRUE /* isQuery */); CDMResultSet *resultSet = pStat->GetResultSet(); resultSet->Next(); TInt64 rowCount = resultSet->GetLargeInt(1); pStat->Close(); return rowCount; }
void CRUTableSyncTaskExecutor::IncEpoch() { TESTPOINT2(CRUGlobals::TESTPOINT140, tableName_); // Crash the remote process TESTPOINT_SEVERE2(CRUGlobals::REMOTE_CRASH_IN_TABLE_SYNC, tableName_); CDMPreparedStatement *pStat = syncTableDynamicContainer_. GetPreparedStatement(INC_EPOCH); BeginTransaction(); ExecuteStatement(*pStat,IDS_RU_EPOCH_INC_FAILED, tableName_.c_string()); CommitTransaction(); TESTPOINT2(CRUGlobals::TESTPOINT141, tableName_); SetState(EX_EPILOGUE); }
void CRURefreshTaskExecutor::ApplyIRCompilerDefaults() { // Always turn on the explain generation for IR commands SetExplainGeneration(); SetAllowOfflineAccess(); if (NO_FORCE == forceFlags_) { return; } // LCOV_EXCL_START :rfi RUASSERT(NULL != pRefreshTEDynamicContainer_); CRUGlobals::GetInstance()->GetJournal().LogMessage( "USING THE FOLLOWING CONTROL STATMENTS :\n"); if (FORCE_CQS & forceFlags_) { ApplyCQSForInternalRefresh(); } if (FORCE_USER_CQS & forceFlags_) { ApplyUserCQSForInternalRefresh(); } if (FORCE_MV_MDAM & forceFlags_) { CDMPreparedStatement *pStat = pRefreshTEDynamicContainer_-> GetPreparedStatement(MV_MDAM_STAT); ExecuteStatement(*pStat, MV_MDAM_STAT); CRUGlobals::GetInstance()->GetJournal().LogMessage( pRefreshTEDynamicContainer_->GetLastSQL(MV_MDAM_STAT)); } if (FORCE_TABLE_MDAM & forceFlags_) { for (Int32 i=FIRST_TBL_STAT;i<pRefreshTEDynamicContainer_->GetNumOfStmt();i++) { CDMPreparedStatement *pStat = pRefreshTEDynamicContainer_-> #pragma nowarn(1506) // warning elimination GetPreparedStatement(i); #pragma warn(1506) // warning elimination if (NULL == pStat) { // No more control statements for table break; } ExecuteStatement(*pStat, i); CRUGlobals::GetInstance()->GetJournal().LogMessage( #pragma nowarn(1506) // warning elimination pRefreshTEDynamicContainer_->GetLastSQL(i)); #pragma warn(1506) // warning elimination } } // LCOV_EXCL_STOP }
void clConsole::SendCommand( const LString& CMDName ) { guard( "%s", CMDName.c_str() ); FSendCommandResult.assign( "" ); if ( CMDName.size() == 0 ) { return; } bool IsScript = ( LStr::GetUpper( LStr::GetToken( CMDName, 1 ) ) == "RS" ); // split command size_t CommandsSeparator = FindCommandsSeparator( CMDName ); LString ThisCMDString = CMDName; LString RestCMDString( "" ); if ( !IsScript ) { if ( CommandsSeparator ) { ThisCMDString = CMDName.substr( 0, CommandsSeparator ); RestCMDString = CMDName.substr( CommandsSeparator, CMDName.length() - CommandsSeparator ); if ( RestCMDString.length() > 0 ) { LStr::pop_front( &RestCMDString ); } } } // extract command name and parameters LString ThisCMDName = LStr::GetToken( ThisCMDString, 1 ); LString ThisCMDParam = ThisCMDString.substr( ThisCMDName.length(), ThisCMDString.length() - ThisCMDName.length() ); if ( ThisCMDParam.length() > 0 ) { LStr::pop_front( &ThisCMDParam ); } LStr::ToUpper( &ThisCMDName ); if ( IsScript ) { // execute script and return ExecuteStatement( ThisCMDParam ); return; } if ( ThisCMDName.find( "WAIT" ) == 0 ) { // Leave the rest of the command until the next frame if ( CommandsSeparator ) { QueryCommand( RestCMDString ); } return; } else { clCommandsList::const_iterator i = FCommandsList.find( ThisCMDName ); if ( i != FCommandsList.end() ) { ( i->second ).Exec( clFileSystem::ReplaceEnvVars( ThisCMDParam ) ); } else { clAliasesList::const_iterator j = FAliasesList.find( ThisCMDName ); if ( j != FAliasesList.end() ) { QueryCommand( j->second ); } else { DisplayError( "Unknown command: " + ThisCMDName ); } } } if ( CommandsSeparator ) { SendCommand( RestCMDString ); } unguard(); }