void pgConn::LogError(const bool quiet) { if (conn) { if (quiet) { wxLogQuietError(wxT("%s"), GetLastError().Trim().c_str()); } else { wxLogError(wxT("%s"), GetLastError().Trim().c_str()); IsAlive(); } } }
pgSet *pgConn::ExecuteSet(const wxString &sql, bool reportError) { // Execute the query and get the status. if (GetStatus() == PGCONN_OK) { PGresult *qryRes; wxLogSql(wxT("Set query (%s:%d): %s"), this->GetHost().c_str(), this->GetPort(), sql.c_str()); SetConnCancel(); qryRes = PQexec(conn, sql.mb_str(*conv)); ResetConnCancel(); lastResultStatus = PQresultStatus(qryRes); SetLastResultError(qryRes); if (lastResultStatus == PGRES_TUPLES_OK || lastResultStatus == PGRES_COMMAND_OK) { pgSet *set = new pgSet(qryRes, this, *conv, needColQuoting); if (!set) { if (reportError) wxLogError(_("Couldn't create a pgSet object!")); else wxLogQuietError(_("Couldn't create a pgSet object!")); PQclear(qryRes); } return set; } else { LogError(!reportError); PQclear(qryRes); } } return new pgSet(); }
bool dbgController::HandleQuery(pgBatchQuery *_qry, const wxString &_err) { if (!_qry) return false; LOCKMUTEX(m_dbgThreadLock); // It is possible that we found one error, while running the previous query // and, called Stop function from it, because of an error found. // That may have released the debugger thread // // In this case, we should exit this flow gracefully instead showing any // error if (!m_dbgThread || !m_dbgThread->IsRunning()) { UNLOCKMUTEX(m_dbgThreadLock); return false; } switch(_qry->ReturnCode()) { case pgQueryResultEvent::PGQ_CONN_LOST: // This is very unlikely, unless we made mistake creating the query case pgQueryResultEvent::PGQ_STRING_INVALID: case PGRES_EMPTY_QUERY: case pgQueryResultEvent::PGQ_ERROR_PREPARE_CALLABLE: case pgQueryResultEvent::PGQ_ERROR_EXECUTE_CALLABLE: case pgQueryResultEvent::PGQ_ERROR_SEND_QUERY: case pgQueryResultEvent::PGQ_ERROR_CONSUME_INPUT: case pgQueryResultEvent::PGQ_RESULT_ERROR: case PGRES_BAD_RESPONSE: case PGRES_NONFATAL_ERROR: case PGRES_FATAL_ERROR: break; // This is unlikely, we do not generate an event, when execution is // cancelled case pgQueryResultEvent::PGQ_EXECUTION_CANCELLED: break; case PGRES_COMMAND_OK: case PGRES_TUPLES_OK: UNLOCKMUTEX(m_dbgThreadLock); return true; // Hmm - where did it come from? // We never call a function, which results into these results // Anyway - we will return true as we have the result case PGRES_COPY_IN: case PGRES_COPY_OUT: UNLOCKMUTEX(m_dbgThreadLock); return true; } m_frm->EnableToolsAndMenus(false); wxTheApp->Yield(true); if (!m_dbgConn->IsAlive()) { UNLOCKMUTEX(m_dbgThreadLock); wxMessageBox( _("Connection to the database server lost, debugging cannot continue!"), _("Connection Lost"), wxICON_ERROR | wxOK); } else { wxString strErr; if (!_err.IsEmpty()) strErr = _err + wxT("\n\n"); strErr += _qry->GetErrorMessage(); UNLOCKMUTEX(m_dbgThreadLock); if (_qry->ReturnCode() == PGRES_FATAL_ERROR) { // We will start start listening for new in-context session, if the // current session is closed. On which, the query/target was // running. // // This allows us to have the same behaviour as the old one. // if (m_sessionType == DBG_SESSION_TYPE_INCONTEXT && m_currTargetPid != wxT("")) { // Let's check if the target pid has stopped or exited after // successful debugging, let's move on and wait for the next // target to hit. wxString isTargetRunning = m_dbgConn->ExecuteScalar(wxString::Format(ms_cmdIsBackendRunning, m_currTargetPid.c_str())); if (isTargetRunning == wxT("0")) { // Reset the current backend-pid of the target m_currTargetPid = wxT(""); m_dbgThread->AddQuery( wxString::Format( ms_cmdWaitForTarget, m_model->GetSession().c_str()), NULL, RESULT_ID_TARGET_READY); m_frm->LaunchWaitingDialog(); return false; } } else { wxMessageBox(_("The calling connection was closed or lost."), _("Connection Lost"), wxICON_ERROR | wxOK); } } else { wxMessageBox(strErr, _("Execution Error"), wxICON_ERROR | wxOK); } wxLogQuietError(strErr); } Stop(); m_terminated = true; m_frm->SetStatusText(_("Debugging aborting...")); return false; }