Int32 sqlci_parser_handle_error(SqlciNode **node, Lng32 retval) { NABoolean syntaxError_ = sqlci_DA.contains(-SQLCI_SYNTAX_ERROR); if (retval && syntaxError_) { if (SqlciEnvGlobal->isReportWriterMode()) { SqlciParseTree = (SqlciNode *)new SqlciRWQueryCmd(SqlciParse_OriginalStr, (Lng32)strlen(SqlciParse_OriginalStr)); assert(SqlciParseTree->isSqlciNode()); *node = SqlciParseTree; sqlci_DA.clear(); // clear the diagonistics return 0; } else if (SqlciEnvGlobal->isMXCSMode()) { SqlciParseTree = (SqlciNode *)new SqlciCSQueryCmd(SqlciParse_OriginalStr, (Lng32)strlen(SqlciParse_OriginalStr)); assert(SqlciParseTree->isSqlciNode()); *node = SqlciParseTree; sqlci_DA.clear(); // clear the diagonistics return 0; } else return retval; } else return retval; }
// sqlci run with input coming in from an infile specified at command line void SqlciEnv::run(char * in_filename, char * input_string) { if ((! in_filename) && (input_string)) { runWithInputString(input_string); return; } interactive_session = 0; // overwrite value from ctor! // This function is called during the initialization phase of MXCI // (SqlciEnv_prologue_to_run). Use specialERROR_ as a flag indicating that // the querry being executed is invoke during MXCI's initialization phase and // that any errors will be fatal. Should an error occur, exit MXCI. SqlciEnv_prologue_to_run(this); SqlCmd::executeQuery("SET SESSION DEFAULT SQL_SESSION 'BEGIN';", this); Int32 retval = 0; SqlciNode * sqlci_node = 0; // input is from a file given at command line (SQLCI -i<filename>). // Create an "OBEY filename" command and process it. char * command = new char[10 + strlen(in_filename)]; strcpy(command, "OBEY "); strcat(command, in_filename); strcat(command, ";"); sqlci_parser(command, command, &sqlci_node,this); delete [] command; void (*intHandler_addr) (Int32); intHandler_addr = interruptHandler; if (sqlci_node) { retval = sqlci_node->process(this); delete sqlci_node; sqlci_node = NULL; displayDiagnostics(); sqlci_DA.clear(); // Clear the DiagnosticsArea for the next command... } if (!retval) // EXIT not seen in the obey file { // create an EXIT command char command[10]; strcpy(command, "exit;"); get_logfile()->WriteAll(">>exit;"); sqlci_parser(command, command, &sqlci_node,this); if (sqlci_node) { retval = sqlci_node->process(this); delete sqlci_node; sqlci_node = NULL; displayDiagnostics(); sqlci_DA.clear(); } } DeleteCriticalSection(&g_CriticalSection); DeleteCriticalSection(&g_InterruptCriticalSection); cleanupSockets(); } // run (in_filename)
SP_HELPER_STATUS CmpSPExtractFunc_ ( Lng32 fieldNo, SP_ROW_DATA rowData, Lng32 fieldLen, void* fieldData, Lng32 casting ) { CmpSPExecDataItemInput* inPtr = (CmpSPExecDataItemInput*)rowData; ULng32 tempNum = (ULng32)fieldNo; ULng32 tempLen = (ULng32)fieldLen; ComDiagsArea* diags = inPtr->SPFuncsDiags(); if ( inPtr->extract(tempNum,(char*)fieldData,tempLen, ((casting==1) ? TRUE : FALSE), diags) < 0 || diags->getNumber() ) { // TODO, convert the errors in diags into error code. diags->clear(); // to be used for next CmpSPExtractFunc_ return SP_ERROR_EXTRACT_DATA; } // test code for assert, check for arkcmp/SPUtil.cpp SP_ERROR_* // for detail description. //#define ASTRING "TestCMPASSERTEXE" //assert( strncmp((char*)fieldData, ASTRING, strlen(ASTRING) != 0 ) ) ; return SP_NO_ERROR; }
void interruptHandler (Int32 signalType) { void (*intHandler_addr) (Int32); intHandler_addr = interruptHandler; Lng32 retcode = 0; // for return of success or failure from handleBreak methods in MACL and RW. UInt32 recoverNeeded = 0; signal(SIGINT, intHandler_addr); // arm the signal for break. // This is for the Break key abend problem in Outside View for NSK. Instead of SIGINT, // SIGQUIT is being sent by the TELSRV people to OSS. We catch it right here. if (TryEnterCriticalSection(&g_CriticalSection)) { Lng32 eCode = SQL_EXEC_Cancel(0); if (eCode ==0) { LeaveCriticalSection(&g_CriticalSection); } else { // retry switch (-eCode) { case CLI_CANCEL_REJECTED: { SqlciEnv s; s.displayDiagnostics(); sqlci_DA.clear(); LeaveCriticalSection(&g_CriticalSection); } break; default: { sqlci_DA << DgSqlCode(SQLCI_BREAK_ERROR, DgSqlCode::WARNING_); SqlciEnv s; s.displayDiagnostics(); sqlci_DA.clear(); LeaveCriticalSection(&g_CriticalSection); } break; } } } }
SP_HELPER_STATUS CmpSPFormatFunc_ (Lng32 fieldNo, SP_ROW_DATA rowData, Lng32 fieldLen, void* fieldData, Lng32 casting) { CmpSPExecDataItemReply* replyPtr = (CmpSPExecDataItemReply*)rowData; #pragma nowarn(262) // warning elimination ULng32 tempNum = (ULng32)fieldNo; ULng32 tempLen = (ULng32)fieldLen; ComDiagsArea* diags = replyPtr->SPFuncsDiags(); if ( replyPtr->moveOutput(fieldNo,(char*)fieldData,tempLen, ((casting==1) ? TRUE : FALSE), diags) < 0 || diags->getNumber() ) { diags->clear(); // to be used for next CmpSPFormatFunc_ return SP_ERROR_FORMAT_DATA; } else return SP_NO_ERROR; }
Int32 sqlci_parser(char *instr, char *origstr, SqlciNode ** node, SqlciEnv *sqlci_env) { Lng32 prevDiags = sqlci_DA.getNumber(); // capture this before parsing // replace any user defined pattern in the query char * newstr = origstr; newstr = SqlCmd::replacePattern(sqlci_env, origstr); Int32 retval = sqlci_parser_subproc(instr, newstr, node, sqlci_env); // There's still some weird error in the Sqlci Lexer // ("OBEY F(S);FC 1;" and "OBEY F;!O;" fail -- bug in the <FNAME> state?). // Here we *KLUDGE* around the problem, by retrying the parse once only. if (retval) { sqlci_parser_syntax_error_cleanup(NULL, sqlci_env); if (!prevDiags && retval > 0) // NOT the -99 from above! { sqlci_DA.clear(); retval = sqlci_parser_subproc(instr, newstr, node, sqlci_env); if (retval) sqlci_parser_syntax_error_cleanup(NULL, sqlci_env); } } if (retval > 0) { SqlciParse_OriginalStr = origstr; retval = sqlci_parser_handle_error(node, retval); } if (newstr != origstr) delete [] newstr; return retval; }
// print MDFWriter errors to cout void SQLJFile::printMDFWriterErrors(char *errFileName) { char args[1024], EorW[10]; Int32 errNum; FILE *errFile = fopen(errFileName, "r"); if (errFile) { // accommodate case of MDFWriter dumping more entries into its errFile // than can fit into the fixed-size diags area. Do this by feeding // and then dumping diags one entry at a time. ComDiagsArea *myDiags = ComDiagsArea::allocate(mxCUMptr->heap()); while (fscanf(errFile, "%s %d ", EorW, &errNum) != EOF) { size_t sLen = 0; if (fgets(args, 1024, errFile) == NULL) { // fgets got EOF or an error args[0] = 0; // empty string *mxCUMptr << FAIL; } else { // fgets got something sLen = strlen(args); // chop off terminating newline if (args[sLen-1] == '\n') { args[sLen-1] = 0; } if (sLen >= 1023) { // diagnostic msg is too long // toss rest of line Int32 nxtCh; do { nxtCh = fgetc(errFile); } while (nxtCh != '\n' && nxtCh != EOF); } } if (!myDiags) { // no diags *mxCUMptr << FAIL; if (sLen >= 1023) { // diagnostic msg is too long cerr << "Diagnostic message is over 1023 characters long." << endl; } // echo error file entry to cerr cerr << EorW << " " << errNum << " " << args << endl; } else { if (sLen >= 1023) { // diagnostic msg is too long *mxCUMptr << WARNING; *myDiags << DgSqlCode(2237); } switch (errNum) { case 2224: case 2225: case 2226: *mxCUMptr << FAIL; *myDiags << DgSqlCode(-errNum); break; case 2227: case 2228: case 2230: *mxCUMptr << FAIL; *myDiags << DgSqlCode(-errNum) << DgString0(args); break; case 2229: *mxCUMptr << ERROR; *myDiags << DgSqlCode(-errNum) << DgString0(args); break; default: *mxCUMptr << (EorW[0]=='E' ? ERROR : (EorW[0]=='W' ? WARNING : FAIL)); *myDiags << DgSqlCode(-2231) << DgInt0(errNum) << DgString0(EorW) << DgString1(args); break; } // end switch NADumpDiags(cerr, myDiags, TRUE); myDiags->clear(); } // end if } // end while if (myDiags) { myDiags->decrRefCount(); } fclose(errFile); } else { *mxCUMptr << FAIL << DgSqlCode(-2218) << DgString0(errFileName); } // clean up temporary file (MDFWriter errors) remove(errFileName); }
short Shape::processNextStmt(SqlciEnv * sqlci_env, FILE * fStream) { short retcode = 0; enum ShapeState { PROCESS_STMT, DONE }; Int32 done = 0; Int32 ignore_toggle = 0; ShapeState state; InputStmt * input_stmt; SqlciNode * sqlci_node = NULL; state = PROCESS_STMT; while (!done) { input_stmt = new InputStmt(sqlci_env); Int32 read_error = 0; if (state != DONE) { read_error = input_stmt->readStmt(fStream, TRUE); if (feof(fStream) || read_error == -99) { if (!input_stmt->isEmpty() && read_error != -4) { // Unterminated statement in obey file. // Make the parser emit an error message. input_stmt->display((UInt16)0, TRUE); input_stmt->logStmt(TRUE); input_stmt->syntaxErrorOnEof(); } state = DONE; } // feof or error (=-99) } // if there is an eof directly after a statement // that is terminated with a semi-colon, process the // statement if (read_error == -4) state = PROCESS_STMT; switch (state) { case PROCESS_STMT: { Int32 ignore_stmt = input_stmt->isIgnoreStmt(); if (ignore_stmt) ignore_toggle = ~ignore_toggle; if (ignore_stmt || ignore_toggle || input_stmt->ignoreJustThis()) { // ignore until stmt following the untoggling ?ignore sqlci_DA.clear(); } else { if (!read_error || read_error == -4) { sqlci_parser(input_stmt->getPackedString(), input_stmt->getPackedString(), &sqlci_node,sqlci_env); if ((sqlci_node) && (sqlci_node->getType() == SqlciNode::SQL_CMD_TYPE)) { delete sqlci_node; SqlCmd sqlCmd(SqlCmd::DML_TYPE, NULL); short retcode = sqlCmd.showShape(sqlci_env, input_stmt->getPackedString()); if (retcode) { delete input_stmt; return retcode; } } input_stmt->display((UInt16)0, TRUE); input_stmt->logStmt(TRUE); } sqlci_env->displayDiagnostics() ; // Clear the DiagnosticsArea for the next command... sqlci_DA.clear(); // if an EXIT statement was seen, then a -1 will be returned // from process. We are done in that case. if (retcode == -1) state = DONE; } } break; case DONE: { done = -1; } break; default: { } break; } // switch on state delete input_stmt; } // while not done return 0; }
short FixCommand::process(SqlciEnv * sqlci_env) { Int32 retval = 0; if (sqlci_env->isOleServer()) { SqlciError (SQLCI_CMD_NOT_SUPPORTED, (ErrorParam *) 0 ); return 0; } // ignore if FC is in an obey file, or stdin redirected from a file // (should we display an informative error message?) if (!sqlci_env->isInteractiveNow()) #pragma nowarn(1506) // warning elimination return retval; #pragma warn(1506) // warning elimination InputStmt *input_stmt = 0, *stmt = 0; // Don't add the FC cmd to the sqlci stmts list. sqlci_env->getSqlciStmts()->remove(); if (cmd != 0) // Character string was provided... { input_stmt = sqlci_env->getSqlciStmts()->get(cmd); } else { if (!cmd_num) input_stmt = sqlci_env->getSqlciStmts()->get(); else { if (neg_num) cmd_num = (sqlci_env->getSqlciStmts()->last_stmt() - cmd_num) + 1; input_stmt = sqlci_env->getSqlciStmts()->get(cmd_num); } } if (input_stmt) { enum { DUNNO, YES, NO }; Int32 is_single_stmt = DUNNO; InputStmt * fc_input_stmt = new InputStmt(sqlci_env); *fc_input_stmt = input_stmt; // Prompt user to fix the input stmt. // Fix() value is 0 if we are to execute (and log and history) new stmt, // -20 if user "aborted" the FC via an EOF or "//" at the prompt // (we must emulate this behavior at the -20 section later on!) // if (fc_input_stmt->fix() != -20) { if (!fc_input_stmt->isEmpty()) { // Clear any syntax errors thrown by InputStmt::fix(); // we'll get to 'em one at a time in this loop sqlci_DA.clear(); // Looping, process one or more commands ("a;b;c;") // on the FC input line. char * packedStr = fc_input_stmt->getPackedString(); do { size_t quotePos; // unterminated quote seen? char packedEndC = '\0'; char * packedEnd = fc_input_stmt->findEnd(packedStr, quotePos); if (!quotePos) { // No unterminated quote if (is_single_stmt == DUNNO) is_single_stmt = (!packedEnd || fc_input_stmt->isEmpty(packedEnd)) ? YES : NO; if (packedEnd) // semicolon seen { packedEndC = *packedEnd; *packedEnd = '\0'; if (is_single_stmt == YES && packedEndC) is_single_stmt = NO; } if (!fc_input_stmt->isEmpty(packedStr)) { if (is_single_stmt == YES) stmt = fc_input_stmt; else stmt = new InputStmt(fc_input_stmt, packedStr); Int32 read_error = 0; // Unterminated stmt (no ";" seen), // so prompt for the rest of it. // If user enters EOF in the appended lines, // then log it, but don't history it or execute it. if (!packedEnd) { read_error = stmt->fix(-1/*append_only*/); packedStr = stmt->getPackedString(); } stmt->logStmt(); if (read_error != -20) // see "abort" note above sqlci_env->getSqlciStmts()->add(stmt); if (!read_error) { SqlciNode * sqlci_node = 0; sqlci_parser(packedStr, packedStr, &sqlci_node, sqlci_env); if (sqlci_node) { retval = sqlci_node->process(sqlci_env); delete sqlci_node; } } sqlci_env->displayDiagnostics(); sqlci_DA.clear(); if (retval == -1) // EXIT command break; } if (packedEnd) { *packedEnd = packedEndC; packedStr = packedEnd; } else break; // terminate the unterminated stmt } else { // If unterminated quote, log it and history it and // display error message and exit the loop; // if just trailing blanks, it's no error, exit the loop. if (!fc_input_stmt->isEmpty(packedStr)) { if (is_single_stmt == DUNNO) { is_single_stmt = YES; stmt = fc_input_stmt; } else stmt = new InputStmt(fc_input_stmt, packedStr); stmt->logStmt(); sqlci_env->getSqlciStmts()->add(stmt); fc_input_stmt->syntaxErrorOnMissingQuote(packedStr); } break; } } while (*packedStr); } } if (is_single_stmt != YES) delete fc_input_stmt; } else { SqlciError(SQLCI_NO_STMT_MATCH, (ErrorParam *) 0); } #pragma nowarn(1506) // warning elimination return retval; #pragma warn(1506) // warning elimination } // end FixCommand::process
short Obey::process(SqlciEnv * sqlci_env) { short retcode = 0; enum ObeyState { SKIP_STMT, PROCESS_STMT, DONE }; if (sqlci_env->isOleServer()) { SqlciError (SQLCI_CMD_NOT_SUPPORTED, (ErrorParam *) 0 ); return 0; } char *name = get_argument(); errno = 0; FILE * file_stream = fopen(name, "r"); if (!file_stream) { #ifndef NA_CASE_INSENSITIVE_FILENAMES static Int32 desensitize = -1; if (desensitize < 0) { const char *env = getenv("SQL_MXCI_CASE_INSENSITIVE_OBEY"); if (!env || !*env || *env == '0') desensitize = 0; else if (*env == '1' || isupper(*env)) desensitize = 'U'; else if (isdigit(*env) || islower(*env)) desensitize = 'L'; else desensitize = 'U'; } if (desensitize) { NABoolean U = (desensitize == 'U'); for (Int32 i = 0; i < 2 && !file_stream; i++, U = !U) { if (U) #pragma nowarn(1506) // warning elimination {for (char *n=name; *n; n++) *n = toupper(*n);} #pragma warn(1506) // warning elimination else #pragma nowarn(1506) // warning elimination {for (char *n=name; *n; n++) *n = tolower(*n);} #pragma warn(1506) // warning elimination file_stream = fopen(name, "r"); } if (!file_stream) { // We've tried the original name aBc, // and ABC and abc, so as a last-ditch effort we try Abc. #pragma nowarn(1506) // warning elimination {for (char *n=name; *n; n++) *n = tolower(*n);} #pragma warn(1506) // warning elimination #pragma nowarn(1506) // warning elimination *name = toupper(*name); #pragma warn(1506) // warning elimination file_stream = fopen(name, "r"); // If all failed, ensure name all upper for prettier error msg if (!file_stream) #pragma nowarn(1506) // warning elimination {for (char *n=name; *n; n++) *n = toupper(*n);} #pragma warn(1506) // warning elimination } } if (!file_stream) #endif { ErrorParam *p1 = new ErrorParam (errno); ErrorParam *p2 = new ErrorParam (name); SqlciError (SQLCI_OBEY_FOPEN_ERROR, p1, p2, (ErrorParam *) 0 ); delete p1; delete p2; return 0; } } short prevEnvObey = sqlci_env->inObeyFile(); sqlci_env->setObey(-1); Int32 done = 0; Int32 ignore_toggle = 0; Int32 veryFirst = 1; ObeyState state; if (!section_name) state = PROCESS_STMT; else state = SKIP_STMT; Int32 section_was_seen = (state == PROCESS_STMT); InputStmt * input_stmt; SqlciNode * sqlci_node = 0; while (!done) { input_stmt = new InputStmt(sqlci_env); Int32 read_error = 0; if(veryFirst == 1) { veryFirst = 0; input_stmt->setVeryFirstLine(); } if (state != DONE) { // If section wasn't seen yet, then suppress echoing of blank lines // in the preceding sections of the obey file as we read thru it. read_error = input_stmt->readStmt(file_stream, !section_was_seen); if (feof(file_stream) || read_error == -99) { if (!section_was_seen && read_error != -99) { // Clear the DiagnosticsArea of any preceding sections' // syntax errors. sqlci_DA.clear(); SqlciError (SQLCI_SECTION_NOT_FOUND, new ErrorParam (section_name), new ErrorParam (name), (ErrorParam *) 0 ); } else if (!input_stmt->isEmpty() && read_error != -4) { // Unterminated statement in obey file. // Make the parser emit an error message. input_stmt->display((UInt16)0); //64bit project: add dummy arg - prevent C++ error input_stmt->logStmt(); input_stmt->syntaxErrorOnEof(); } state = DONE; } // if there is an eof directly after a statement // that is terminated with a semi-colon, process the // statement if (read_error == -4) state = PROCESS_STMT; } switch (state) { case SKIP_STMT: { if (input_stmt->sectionMatches(section_name)) { input_stmt->display((UInt16)0); //64bit project: add dummy arg - prevent C++ error state = PROCESS_STMT; section_was_seen = (state == PROCESS_STMT); // Clear the DiagnosticsArea for the section we're to process // (clear it of any preceding sections' syntax errors). sqlci_DA.clear(); } } break; case PROCESS_STMT: { #pragma nowarn(1506) // warning elimination short section_match = input_stmt->sectionMatches(); #pragma warn(1506) // warning elimination if (!section_name && section_match) { input_stmt->display((UInt16)0); //64bit project: add dummy arg - prevent C++ error if (sqlci_env->logCommands()) sqlci_env->get_logfile()->setNoLog(FALSE); input_stmt->logStmt(); if (sqlci_env->logCommands()) sqlci_env->get_logfile()->setNoLog(TRUE); break; } if ((!section_name) || (!section_match)) { input_stmt->display((UInt16)0); //64bit project: add dummy arg - prevent C++ error if (sqlci_env->logCommands()) sqlci_env->get_logfile()->setNoLog(FALSE); input_stmt->logStmt(); if (sqlci_env->logCommands()) sqlci_env->get_logfile()->setNoLog(TRUE); Int32 ignore_stmt = input_stmt->isIgnoreStmt(); if (ignore_stmt) ignore_toggle = ~ignore_toggle; if (ignore_stmt || ignore_toggle || input_stmt->ignoreJustThis()) { // ignore until stmt following the untoggling ?ignore sqlci_DA.clear(); } else { if (!read_error || read_error == -4) { #pragma nowarn(1506) // warning elimination retcode = sqlci_parser(input_stmt->getPackedString(), input_stmt->getPackedString(), &sqlci_node,sqlci_env); #pragma warn(1506) // warning elimination if (sqlci_node) { retcode = sqlci_node->process(sqlci_env); if (retcode == SQL_Canceled) { state = DONE; retcode = 0; } delete sqlci_node; } if (retcode > 0) { sqlci_env->setPrevErrFlushInput(); retcode = 0; } } } sqlci_env->displayDiagnostics() ; // Clear the DiagnosticsArea for the next command... sqlci_DA.clear(); // if an EXIT statement was seen, then a -1 will be returned // from process. We are done in that case. if (retcode == -1) { state = DONE; fclose(file_stream); done = -1; } } else { state = DONE; } } break; case DONE: { fclose(file_stream); done = -1; } break; default: { } break; } // switch on state // Delete the stmt if it's not one of those we saved on the history list if (!input_stmt->isInHistoryList()) delete input_stmt; if (breakReceived) { state = DONE; sqlci_env->resetPrevErrFlushInput(); retcode = 0; } } // while not done sqlci_env->setObey(prevEnvObey); return retcode; }
Int32 SqlciEnv::executeCommands(InputStmt *& input_stmt) { Int32 retval = 0; Int32 ignore_toggle = 0; SqlciNode * sqlci_node = 0; NABoolean inputPassedIn = (input_stmt ? TRUE : FALSE); try { while (!retval) { total_opens = 0; total_closes = 0; // This is new'd here, deleted when history buffer fills up, // in SqlciStmts::add/StmtEntry::set if (NOT inputPassedIn) input_stmt = new InputStmt(this); Int32 read_error = 0; if (NOT inputPassedIn) read_error = input_stmt->readStmt(NULL/*i.e. input is stdin*/); prev_err_flush_input = 0; if (cin.eof() || read_error == -99) { // allow the other thread to process Sleep(50); // milliseconds if (!input_stmt->isEmpty()) { // Unterminated statement in input file (redirected stdin). // Make the parser emit an error message. if (!isInteractiveSession()) input_stmt->display((UInt16)0); input_stmt->logStmt(); input_stmt->syntaxErrorOnEof(); displayDiagnostics(); sqlci_DA.clear(); } char command[10]; strcpy(command, ">>exit;"); if (!isInteractiveSession()) get_logfile()->WriteAll(command); else if (get_logfile()->IsOpen()) #pragma nowarn(1506) // warning elimination get_logfile()->Write(command, strlen(command)); #pragma warn(1506) // warning elimination sqlci_parser(&command[2], &command[2], &sqlci_node,this); if (sqlci_node) { retval = sqlci_node->process(this); delete sqlci_node; sqlci_node = NULL; } } else { if (!isInteractiveSession()) input_stmt->display((UInt16)0); if (logCommands()) get_logfile()->setNoLog(FALSE); input_stmt->logStmt(); if (logCommands()) get_logfile()->setNoLog(TRUE); if (!input_stmt->sectionMatches()) { Int32 ignore_stmt = input_stmt->isIgnoreStmt(); if (ignore_stmt) ignore_toggle = ~ignore_toggle; if (ignore_stmt || ignore_toggle || input_stmt->ignoreJustThis()) { // ignore until stmt following the untoggling ?ignore sqlci_DA.clear(); } else { getSqlciStmts()->add(input_stmt); if (!read_error) { retval = sqlci_parser(input_stmt->getPackedString(), input_stmt->getPackedString(), &sqlci_node, this); if (sqlci_node) { retval = sqlci_node->process(this); delete sqlci_node; sqlci_node = NULL; if (retval == SQL_Canceled) retval = 0; } else { // pure MXCI synatax error. Reset retval retval = 0; } } if (retval > 0) { if (!eol_seen_on_input) { prev_err_flush_input = -1; } retval = 0; } } // else }// if } // else if ( read_error == -20) { sqlci_DA << DgSqlCode(SQLCI_BREAK_RECEIVED, DgSqlCode::WARNING_); } if (read_error == SqlciEnv::MAX_FRAGMENT_LEN_OVERFLOW && !eolSeenOnInput() ) setPrevErrFlushInput(); displayDiagnostics(); sqlci_DA.clear(); // Clear the DiagnosticsArea for the next command... if (total_opens != total_closes) { char buf[100]; sprintf(buf, "total opens = %d, total closes = %d", total_opens, total_closes); #pragma nowarn(1506) // warning elimination get_logfile()->WriteAll(buf, strlen(buf)); #pragma warn(1506) // warning elimination } // Delete the stmt if not one of those we saved on the history list if (!input_stmt->isInHistoryList()) delete input_stmt; if (inputPassedIn) retval = 1; } // while if (retval == SQL_Canceled) return SQL_Canceled; else return 0; } catch(EHBreakException&) { sqlci_DA << DgSqlCode(SQLCI_BREAK_RECEIVED, DgSqlCode::WARNING_); displayDiagnostics(); sqlci_DA.clear(); // Clear the DiagnosticsArea for the next command... if (sqlci_node) delete sqlci_node; sqlci_node = NULL; cin.clear(); // NOTE: EnterCriticalSection has been done in ThrowBreakException() LeaveCriticalSection(&g_CriticalSection); return -1; } catch(...) { return 1; } } // executeCommands
BOOL CtrlHandler(DWORD ctrlType) { if (Sqlci_PutbackChar == LOOK_FOR_BREAK) // see InputStmt.cpp Sqlci_PutbackChar = FOUND_A_BREAK; breakReceived =1; sqlci_DA << DgSqlCode(SQLCI_BREAK_RECEIVED, DgSqlCode::WARNING_); switch (ctrlType) { case CTRL_C_EVENT: case CTRL_BREAK_EVENT: if (TryEnterCriticalSection(&g_CriticalSection)) { Lng32 eCode = SQL_EXEC_Cancel(0); if (eCode ==0) { sqlci_DA << DgSqlCode( -SQL_Canceled, DgSqlCode::WARNING_); LeaveCriticalSection(&g_CriticalSection); } else { // retry switch (-eCode) { case CLI_CANCEL_REJECTED: { sqlci_DA << DgSqlCode(SQLCI_BREAK_REJECTED, DgSqlCode::WARNING_); //sqlci_DA << DgSqlCode(SQLCI_COMMAND_NOT_CANCELLED, DgSqlCode::WARNING_); SqlciEnv s; s.displayDiagnostics(); sqlci_DA.clear(); //breakReceived = 0; LeaveCriticalSection(&g_CriticalSection); } break; default: { sqlci_DA << DgSqlCode(SQLCI_BREAK_ERROR, DgSqlCode::WARNING_); SqlciEnv s; s.displayDiagnostics(); sqlci_DA.clear(); LeaveCriticalSection(&g_CriticalSection); } break; } } } return TRUE; break; case CTRL_CLOSE_EVENT: case CTRL_LOGOFF_EVENT: case CTRL_SHUTDOWN_EVENT: if (TryEnterCriticalSection(&g_CriticalSection)) { Lng32 eCode = SQL_EXEC_Cancel(0); if (eCode ==0) { sqlci_DA << DgSqlCode( -SQL_Canceled, DgSqlCode::WARNING_); LeaveCriticalSection(&g_CriticalSection); } else { // retry switch (-eCode) { case CLI_CANCEL_REJECTED: { SqlciEnv s; s.displayDiagnostics(); sqlci_DA.clear(); LeaveCriticalSection(&g_CriticalSection); } break; default: { sqlci_DA << DgSqlCode(SQLCI_BREAK_ERROR, DgSqlCode::WARNING_); SqlciEnv s; s.displayDiagnostics(); sqlci_DA.clear(); LeaveCriticalSection(&g_CriticalSection); } break; } } } return TRUE; break; default: return FALSE; } }