diff --git a/pgadmin/ctl/ctlSQLResult.cpp b/pgadmin/ctl/ctlSQLResult.cpp index 0b63114..1c27259 100644 --- a/pgadmin/ctl/ctlSQLResult.cpp +++ b/pgadmin/ctl/ctlSQLResult.cpp @@ -27,7 +27,7 @@ ctlSQLResult::ctlSQLResult(wxWindow *parent, pgConn *_conn, wxWindowID id, const : ctlSQLGrid(parent, id, pos, size) { conn = _conn; - thread = 0; + thread = NULL; SetTable(new sqlResultTable(), true); @@ -45,11 +45,13 @@ ctlSQLResult::~ctlSQLResult() if (thread) { - thread->CancelExecution(); - thread->Wait(); + if (thread->IsRunning()) + { + thread->CancelExecution(); + thread->Wait(); + } delete thread; - thread = NULL; } } @@ -130,16 +132,6 @@ int ctlSQLResult::Execute(const wxString &query, int resultToRetrieve, wxWindow colTypes.Empty(); colTypClasses.Empty(); - if (thread) - { - thread->CancelExecution(); - thread->Wait(); - - delete thread; - thread = NULL; - } - - thread = new pgQueryThread(conn, query, resultToRetrieve, caller, eventId, data); if (thread->Create() != wxTHREAD_NO_ERROR) @@ -161,8 +153,14 @@ int ctlSQLResult::Abort() { ((sqlResultTable *)GetTable())->SetThread(0); - thread->CancelExecution(); - thread->Wait(); + if (thread->IsRunning()) + { + thread->CancelExecution(); + thread->Wait(); + } + + delete thread; + thread = NULL; } return 0; } @@ -269,7 +267,12 @@ wxString ctlSQLResult::GetErrorMessage() pgError ctlSQLResult::GetResultError() { - return thread->GetResultError(); + if (thread) + return thread->GetResultError(); + + pgError dummy; + memset(&dummy, 0, sizeof(dummy)); + return dummy; } long ctlSQLResult::NumRows() const @@ -399,7 +402,7 @@ wxString sqlResultTable::GetValue(int row, int col) sqlResultTable::sqlResultTable() { - thread = 0; + thread = NULL; } int sqlResultTable::GetNumberRows() diff --git a/pgadmin/debugger/dbgEvents.cpp b/pgadmin/debugger/dbgEvents.cpp index bac466f..ae04b5f 100644 --- a/pgadmin/debugger/dbgEvents.cpp +++ b/pgadmin/debugger/dbgEvents.cpp @@ -206,8 +206,8 @@ void dbgController::ResultTargetComplete(pgQueryResultEvent &_ev) if (m_execConnThread->IsRunning()) { m_execConnThread->CancelExecution(); + m_execConnThread->Wait(); } - m_execConnThread->Wait(); pgConn *execConn = m_execConnThread->GetConn(); delete m_execConnThread; diff --git a/pgadmin/debugger/dlgDirectDbg.cpp b/pgadmin/debugger/dlgDirectDbg.cpp index cc0cba9..68f93fe 100644 --- a/pgadmin/debugger/dlgDirectDbg.cpp +++ b/pgadmin/debugger/dlgDirectDbg.cpp @@ -518,9 +518,11 @@ void dlgDirectDbg::OnCancel(wxCommandEvent &_ev) { if (m_thread) { - m_thread->CancelEval(); - - m_thread->Wait(); + if (m_thread->IsRunning()) + { + m_thread->CancelEval(); + m_thread->Wait(); + } delete m_thread; m_thread = NULL; @@ -756,8 +758,11 @@ void dlgDirectDbg::ResultArgsUpdated(wxCommandEvent &_ev) if (m_thread) { - m_thread->CancelEval(); - m_thread->Wait(); + if (m_thread->IsRunning()) + { + m_thread->CancelEval(); + m_thread->Wait(); + } delete m_thread; m_thread = NULL; @@ -780,9 +785,11 @@ void dlgDirectDbg::ResultArgsUpdateError(wxCommandEvent &_ev) { if (m_thread) { - m_thread->CancelEval(); - - m_thread->Wait(); + if (m_thread->IsRunning()) + { + m_thread->CancelEval(); + m_thread->Wait(); + } delete m_thread; m_thread = NULL; @@ -798,8 +805,11 @@ void dlgDirectDbg::ResultArgsUpdateError(wxCommandEvent &_ev) if (m_thread) { - m_thread->CancelEval(); - m_thread->Wait(); + if (m_thread->IsRunning()) + { + m_thread->CancelEval(); + m_thread->Wait(); + } delete m_thread; m_thread = NULL;