bool pgsApplication::RunThread() { bool created = false; if (m_thread != 0 && m_thread->Create() == wxTHREAD_NO_ERROR) { m_thread->SetPriority(WXTHREAD_MIN_PRIORITY); if (m_thread->Run() == wxTHREAD_NO_ERROR) { created = true; } } if (created) { wxLogScript(wxT("Running...")); return true; } else { wxLogError(wxT("PGSCRIPT: Thread error")); pdelete(m_thread); return false; } }
void pgsApplication::Terminate() { if (IsRunning()) { wxLogScript(wxT("Deleting pgScript")); m_thread->Delete(); } }
pgsApplication::~pgsApplication() { if (m_defined_conn) { pdelete(m_connection); } wxLogScript(wxT("Application destroyed")); }
void pgsApplication::Wait() { if (IsRunning()) { wxLogScript(wxT("Waiting for pgScript")); m_mutex.Wait(); m_mutex.Post(); } }
void pgsProgram::eval(pgsStmtList *stmt_list) { wxLogScript(wxT("Entering program")); try { stmt_list->eval(m_vars); } catch (const pgsException &) { } catch (const std::exception &) { } pgsStmtList::m_exception_thrown = false; wxLogScript(wxT("Leaving program")); }
pgsApplication::pgsApplication(const wxString & host, const wxString & database, const wxString & user, const wxString & password, int port) : m_mutex(1, 1), m_stream(1, 1), m_connection(pnew pgConn(host, database, user, password, port)), m_defined_conn(true), m_thread(0), m_caller(0) { if (m_connection->GetStatus() != PGCONN_OK) { wxLogError(wxT("PGSCRIPT: Cannot connect to database %s:%d/%s with ") wxT("credentials '%s'/'%s'"), host.c_str(), port, database.c_str(), user.c_str(), password.c_str()); } wxLogScript(wxT("Application created")); }
void pgsApplication::Complete() { // If last_error_line() == -1 then there was no error // Else get the line number where the error occurred m_last_error_line = m_thread->last_error_line(); #if !defined(PGSCLI) if (m_caller != 0) { wxCommandEvent resultEvent(wxEVT_COMMAND_MENU_SELECTED, m_event_id); m_caller->AddPendingEvent(resultEvent); } #endif // PGSCLI wxLogScript(wxT("Execution completed")); }
pgsApplication::pgsApplication(pgConn * connection) : m_mutex(1, 1), m_stream(1, 1), m_connection(connection), m_defined_conn(false), m_thread(0), m_caller(0) { wxLogScript(wxT("Application created")); }