int timeout_err_handler(DBPROCESS * dbproc, int severity, int dberr, int oserr, char *dberrstr, char *oserrstr) { /* * For server messages, cancel the query and rely on the * message handler to spew the appropriate error messages out. */ if (dberr == SYBESMSG) return INT_CANCEL; if (dberr == SYBETIME) { fprintf(stderr, "%d timeouts received in %ld seconds, ", ++ntimeouts, (long int) (time(NULL) - start_time)); if (ntimeouts > max_timeouts) { if (++ncancels > 1) { fprintf(stderr, "could not timeout cleanly, breaking connection\n"); ncancels = 0; return INT_CANCEL; } fprintf(stderr, "lost patience, cancelling (allowing 10 seconds)\n"); if (dbsettime(10) == FAIL) fprintf(stderr, "... but dbsettime() failed in error handler\n"); return INT_TIMEOUT; } fprintf(stderr, "continuing to wait\n"); return INT_CONTINUE; } ntimeouts = 0; /* reset */ fprintf(stderr, "DB-LIBRARY error (severity %d, dberr %d, oserr %d, dberrstr %s, oserrstr %s):\n", severity, dberr, oserr, dberrstr ? dberrstr : "(null)", oserrstr ? oserrstr : "(null)"); fflush(stderr); /* * If the dbprocess is dead or the dbproc is a NULL pointer and * we are not in the middle of logging in, then we need to exit. * We can't do anything from here on out anyway. * It's OK to end up here in response to a dbconvert() that * resulted in overflow, so don't exit in that case. */ if ((dbproc == NULL) || DBDEAD(dbproc)) { if (dberr != SYBECOFL) { fprintf(stderr, "error: dbproc (%p) is %s, goodbye\n", dbproc, dbproc? (DBDEAD(dbproc)? "DEAD" : "OK") : "NULL"); exit(255); } } return INT_CANCEL; }
static int CS_PUBLIC qTdsErrHandler(DBPROCESS* dbproc, int /*severity*/, int dberr, int /*oserr*/, char* dberrstr, char* oserrstr) { QTDSResultPrivate* p = errs()->value(dbproc); if (!p) { qWarning("QTDSDriver error (%d): [%s] [%s]", dberr, dberrstr, oserrstr); return INT_CANCEL; } /* * If the process is dead or NULL and * we are not in the middle of logging in... */ if((dbproc == NULL || DBDEAD(dbproc))) { qWarning("QTDSDriver error (%d): [%s] [%s]", dberr, dberrstr, oserrstr); return INT_CANCEL; } QString errMsg = QString::fromLatin1("%1 %2\n").arg(QLatin1String(dberrstr)).arg( QLatin1String(oserrstr)); errMsg += p->getErrorMsgs(); p->lastError = qMakeError(errMsg, QSqlError::UnknownError, dberr); p->clearErrorMsgs(); return INT_CANCEL ; }
/** * \ingroup dblib_internal * \brief check interrupts for libtds. * * \param vdbproc a DBPROCESS pointer, contains all information needed by db-lib to manage communications with the server. * \sa DBDEAD(), dbsetinterrupt(). */ int _dblib_check_and_handle_interrupt(void * vdbproc) { DBPROCESS * dbproc = (DBPROCESS*) vdbproc; int ret = INT_CONTINUE; assert( ! (dbproc == NULL && DBDEAD(dbproc)) ); /* a non-process can't be a dead process */ if (dbproc->chkintr == NULL || dbproc->hndlintr == NULL) return INT_CONTINUE; tdsdump_log(TDS_DBG_FUNC, "tds_int_handler %p [%p, %p]", dbproc, dbproc->chkintr, dbproc->hndlintr); if (dbproc->chkintr(dbproc)){ switch (ret = dbproc->hndlintr(dbproc)) { case INT_EXIT: tdsdump_log(TDS_DBG_FUNC, "dbproc->hndlintr returned INT_EXIT, goodbye!\n"); exit(1); case INT_CANCEL: tdsdump_log(TDS_DBG_FUNC, "dbproc->hndlintr returned INT_CANCEL\n"); break; case INT_CONTINUE: tdsdump_log(TDS_DBG_FUNC, "dbproc->hndlintr returned INT_CONTINUE\n"); break; default: tdsdump_log(TDS_DBG_FUNC, "dbproc->hndlintr returned an invalid value (%d), returning INT_CONTINUE\n", ret); ret = INT_CONTINUE; break; } } return ret; }
int syb_err_handler(DBPROCESS * dbproc, int severity, int dberr, int oserr, char *dberrstr, char *oserrstr) { /* *For server messages, cancel the query and rely on the *message handler to spew the appropriate error messages out. */ if (dberr == SYBESMSG) return INT_CANCEL; fprintf(stderr, "DB-LIBRARY error (severity %d, dberr %d, oserr %d, dberrstr %s, oserrstr %s):\n", severity, dberr, oserr, dberrstr ? dberrstr : "(null)", oserrstr ? oserrstr : "(null)"); fflush(stderr); /* ** If the dbprocess is dead or the dbproc is a NULL pointer and ** we are not in the middle of logging in, then we need to exit. ** We can't do anything from here on out anyway. ** It's OK to end up here in response to a dbconvert() that ** resulted in overflow, so don't exit in that case. **/ if ((dbproc == NULL) || DBDEAD(dbproc)) { if (dberr != SYBECOFL) { exit(255); } } exit(-1); return INT_CANCEL; }
RETCODE CDBL_Connection::CheckDead(RETCODE rc) { if (rc == FAIL) { if (DBDEAD(GetDBLibConnection()) == TRUE) { CDB_ClientEx ex(DIAG_COMPILE_INFO, 0, "Database connection is closed", eDiag_Error, 220000); GetDBLExceptionStorage().Accept(ex); } else { CDB_ClientEx ex(DIAG_COMPILE_INFO, 0, "dblib function call failed", eDiag_Error, 220001); GetDBLExceptionStorage().Accept(ex); } } CheckFunctCall(); return rc; }
bool CDBL_Connection::Refresh() { // close all commands first DeleteAllCommands(); // cancel all pending commands if (Check(dbcancel(GetDBLibConnection())) != CS_SUCCEED) return false; // check the connection status return DBDEAD(GetDBLibConnection()) == FALSE; }
int err_handler(DBPROCESS* dbproc, int severity, int dberr, int oserr, char* dberrstr, char* oserrstr){ if ((dbproc == NULL) || (DBDEAD(dbproc))) return(INT_EXIT); else { fprintf (ERR_CH, "DB-Library error:\n\t%s\n", dberrstr); if (oserr != DBNOERR) fprintf (ERR_CH, "Operating-system error:\n\t%s\n", oserrstr); return(INT_CANCEL); } }
int syb_err_handler(DBPROCESS * dbproc, int severity, int dberr, int oserr, char *dberrstr, char *oserrstr) { int *pexpected_dberr; /* * For server messages, cancel the query and rely on the * message handler to spew the appropriate error messages out. */ if (dberr == SYBESMSG) return INT_CANCEL; /* * If the user data indicates this is an expected error message (because we're testing the * error propogation, say) then indicate this message was anticipated. */ if (dbproc != NULL) { pexpected_dberr = (int *) dbgetuserdata(dbproc); if (pexpected_dberr && *pexpected_dberr == dberr) { fprintf(stdout, "OK: anticipated error %d (%s) arrived\n", dberr, dberrstr); *pexpected_dberr = 0; return INT_CANCEL; } } fflush(stdout); fprintf(stderr, "DB-LIBRARY error (dberr %d (severity %d): \"%s\"; oserr %d: \"%s\")\n", dberr, severity, dberrstr ? dberrstr : "(null)", oserr, oserrstr ? oserrstr : "(null)"); fflush(stderr); /* * If the dbprocess is dead or the dbproc is a NULL pointer and * we are not in the middle of logging in, then we need to exit. * We can't do anything from here on out anyway. * It's OK to end up here in response to a dbconvert() that * resulted in overflow, so don't exit in that case. */ if ((dbproc == NULL) || DBDEAD(dbproc)) { if (dberr != SYBECOFL) { exit(255); } } if (severity) { fprintf(stderr, "error: no unanticipated errors allowed in unit tests\n"); exit(EXIT_FAILURE); } return INT_CANCEL; }
int err_handler(DBPROCESS *dbproc, int severity, int dberr, int oserr, char *dberrstr, char *oserrstr) { if ((dbproc == NULL) || (DBDEAD(dbproc))) return(INT_EXIT); else { errfile << ERROR_PREFIX << "DB-Library error: " << dberrstr << endl; if (oserr != DBNOERR) errfile << ERROR_PREFIX << "Operating-system error: " << oserrstr << endl; return(INT_CANCEL); } }
int err_handler(DBPROCESS * dbproc, int severity, int dberr, int oserr, char *dberrstr, char *oserrstr) { if ((dbproc == NULL) || (DBDEAD(dbproc))) { return (INT_EXIT); } if (dberr != SYBESMSG) { fprintf(stdout, "DB-LIBRARY error:\n\t%s\n", dberrstr); } if (oserr != DBNOERR) { fprintf(stdout, "Operating-system error:\n\t%s\n", oserrstr); } return (INT_CANCEL); }
int CS_PUBLIC err_handler ( DBPROCESS *db_err_proc, int severity, int dberr, int oserr, char *dberrstr, char *oserrstr) { if ((severity > 0) && (dberr != SYBESMSG)) /* `sql server message': do by `msg_handler ()' */ { error_number = dberr; if ((db_err_proc == NULL) || (DBDEAD (db_err_proc))) { if (mes_flag) { strcat (error_message, "\n"); strcat (error_message, "DB-Library error: unable to open database"); } else { strcpy (error_message, "DB-Library error: unable to open database"); } } else { if (mes_flag) { strcat (error_message, "\n"); strcat (error_message, "DB-Library error: "); } else { strcpy (error_message, "DB-Library error: "); } strcat (error_message, dberrstr); if (oserr != DBNOERR) { strcat (error_message, "Operating-system error: "); strcat (error_message, oserrstr); } } } syb_terminate_order (process_to_descriptor (db_err_proc)); return (INT_CANCEL); }
/************************************************************************* * * Function: sql_query * * Purpose: Issue a query to the database * *************************************************************************/ static int sql_query(SQLSOCK *sqlsocket, SQL_CONFIG *config, char *querystr) { rlm_sql_freetds_sock *freetds_sock = sqlsocket->conn; if (freetds_sock->dbproc == NULL || DBDEAD(freetds_sock->dbproc)) { radlog(L_ERR, "rlm_sql_freetds (%s): Socket not connected", config->xlat_name); return SQL_DOWN; } if ((dbcmd(freetds_sock->dbproc, querystr)) == FAIL) { radlog(L_ERR, "rlm_sql_freetds (%s): Unable to allocate SQL query", config->xlat_name); return -1; } if ((dbsqlexec(freetds_sock->dbproc)) == FAIL) { radlog(L_ERR, "rlm_sql_freetds (%s): SQL query failed", config->xlat_name); return -1; } return 0; }
int syb_msg_handler(DBPROCESS * dbproc, DBINT msgno, int msgstate, int severity, char *msgtext, char *srvname, char *procname, int line) { char var_value[31]; int i; char *c; /* ** Check for "database changed", or "language changed" messages from ** the client. If we get one of these, then we need to pull the ** name of the database or charset from the message and set the ** appropriate variable. **/ if (msgno == 5701 || /* database context change */ msgno == 5703 || /* language changed */ msgno == 5704) { /* charset changed */ /* fprintf( stderr, "msgno = %d: %s\n", msgno, msgtext ) ; */ if (msgtext != NULL && (c = strchr(msgtext, '\'')) != NULL) { i = 0; for (++c; i <= 30 && *c != '\0' && *c != '\''; ++c) var_value[i++] = *c; var_value[i] = '\0'; } return 0; } /* ** If the severity is something other than 0 or the msg number is ** 0 (user informational messages). **/ if (severity >= 0 || msgno == 0) { /* ** If the message was something other than informational, and ** the severity was greater than 0, then print information to ** stderr with a little pre-amble information. **/ if (msgno > 0 && severity > 0) { fprintf(stderr, "Msg %d, Level %d, State %d\n", (int) msgno, (int) severity, (int) msgstate); fprintf(stderr, "Server '%s'", srvname); if (procname != NULL && *procname != '\0') fprintf(stderr, ", Procedure '%s'", procname); if (line > 0) fprintf(stderr, ", Line %d", line); fprintf(stderr, "\n"); fprintf(stderr, "%s\n", msgtext); fflush(stderr); } else { /* ** Otherwise, it is just an informational (e.g. print) message ** from the server, so send it to stdout. **/ fprintf(stdout, "%s\n", msgtext); fflush(stdout); } } /* ** If the dbprocess is dead or the dbproc is a NULL pointer and ** we are not in the middle of logging in, then we need to exit. ** We can't do anything from here on out anyway. ** It's OK to end up here in response to a dbconvert() that ** resulted in overflow, so don't exit in that case. **/ if ((dbproc == NULL) || DBDEAD(dbproc)) { if (msgno != SYBECOFL) { exit(255); } } return 0; }
bool CDBL_Connection::IsAlive() { return DBDEAD(GetDBLibConnection()) == FALSE; }