Index: pgadmin/include/frm/frmQuery.h =================================================================== --- pgadmin/include/frm/frmQuery.h (revision 7943) +++ pgadmin/include/frm/frmQuery.h (working copy) @@ -197,6 +197,10 @@ bool aborted; bool lastFileFormat; + // A simple mutex-like flag to prevent concurrent script execution. + // Required because the pgScript parser isn't currently thread-safe :-( + static bool ms_pgScriptRunning; + DECLARE_EVENT_TABLE() }; Index: pgadmin/frm/frmQuery.cpp =================================================================== --- pgadmin/frm/frmQuery.cpp (revision 7943) +++ pgadmin/frm/frmQuery.cpp (working copy) @@ -75,6 +75,12 @@ #define CTRLID_CONNECTION 4200 #define CTRLID_DATABASELABEL 4201 +// Initialize execution 'mutex'. As this will always run in the +// main thread, there aren't any real concurrency issues, so +// a simple flag will suffice. +// Required because the pgScript parser isn't currently thread-safe :-( +bool frmQuery::ms_pgScriptRunning = false; + BEGIN_EVENT_TABLE(frmQuery, pgFrame) EVT_ERASE_BACKGROUND( frmQuery::OnEraseBackground) EVT_SIZE( frmQuery::OnSize) @@ -1863,6 +1869,15 @@ if (query.IsNull()) return; + // Make sure pgScript is not already running + // Required because the pgScript parser isn't currently thread-safe :-( + if (frmQuery::ms_pgScriptRunning == true) + { + wxMessageBox(_("Concurrent execution of pgScripts is not supported at this time."), _("pgScript already running."), wxICON_WARNING); + return; + } + frmQuery::ms_pgScriptRunning = true; + // Clear markers and indicators sqlQuery->MarkerDeleteAll(0); sqlQuery->StartStyling(0, wxSTC_INDICS_MASK); @@ -2235,6 +2250,9 @@ // Reset tools setTools(false); + // Unlock our pseudo-mutex thingy + frmQuery::ms_pgScriptRunning = false; + // Manage timer elapsedQuery = wxGetLocalTimeMillis() - startTimeQuery; SetStatusText(elapsedQuery.ToString() + wxT(" ms"), STATUSPOS_SECS);