void frmQuery::OnExecScript(wxCommandEvent& event)
{
+ // Get the script
+ wxString query = sqlQuery->GetSelectedText();
+ if (query.IsNull())
+ query = sqlQuery->GetText();
+ if (query.IsNull())
+ return;
+
// Clear markers and indicators
sqlQuery->MarkerDeleteAll(0);
sqlQuery->StartStyling(0, wxSTC_INDICS_MASK);
pgScript->ClearSymbols();
// Parse script
- pgScript->ParseString(sqlQuery->GetText(), pgsOutput);
+ pgScript->ParseString(query, pgsOutput);
pgsTimer->Start(20);
aborted = false;
}
SetStatusText(_("pgScript completed."), STATUSPOS_MSGS);
wxString str = _("Total pgScript runtime: ") + elapsedQuery.ToString() + wxT(" ms.\n\n");
msgHistory->AppendText(str);
+
+ // Check whether there was an error/exception
+ if (pgScript->errorOccurred() && pgScript->errorLine() >= 1)
+ {
+ // Find out what the line number is
+ int selStart = sqlQuery->GetSelectionStart(), selEnd = sqlQuery->GetSelectionEnd();
+ if (selStart == selEnd)
+ selStart = 0;
+ SetStatusText(wxString() << selStart, STATUSPOS_MSGS);
+ int line = 0, maxLine = sqlQuery->GetLineCount();
+ while (line < maxLine && sqlQuery->GetLineEndPosition(line) < selStart)
+ line++;
+ line += pgScript->errorLine() - 1;
+
+ // Mark the line where the error occurred
+ sqlQuery->MarkerAdd(line, 0);
+
+ // Go to that line
+ sqlQuery->GotoPos(sqlQuery->GetLineEndPosition(line));
+ }
}
void frmQuery::writeScriptOutput()
/** pgAdmin specific: post this event when m_thread is done. */
long m_event_id;
+ /** Location of the last error if there was one. */
+ int m_last_error_line;
+
public:
/** Creates an application and creates a connection. */
/** Releases the lock on the output stream. */
void UnlockOutput();
+ /** Was there an error? */
+ bool errorOccurred() const;
+
+ /** Get the position (line) of the last error. */
+ int errorLine() const;
+
private:
/** Common method for parse_file & parse_string: runs the thread. */
/** If set it is the encoding used in the file to parse. */
wxMBConv * m_conv;
+ /** Location of the last error if there was one otherwise -1 */
+ int m_last_error_line;
+
public:
/** Parses a file with the provided encoding. */
/** Releases the lock on the output stream. */
void UnlockOutput();
+ /** Set the position (line) of the last error. */
+ void last_error_line(int line);
+
+ /** Get the position (line) of the last error. */
+ int last_error_line() const;
+
private:
pgsThread(const pgsThread & that);
{
if (!IsRunning())
{
+ m_last_error_line = -1;
m_thread = new pgsThread(m_vars, m_mutex, m_connection,
file, out, *this, conv);
return RunThread();
{
if (!IsRunning())
{
+ m_last_error_line = -1;
m_thread = new pgsThread(m_vars, m_mutex, m_connection,
string, out, *this);
return RunThread();
m_caller->AddPendingEvent(resultEvent);
}
#endif // PGSCLI
+
+ // 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();
wxLogScript(wxT("Execution completed"));
}
{
m_stream.Post();
}
+
+bool pgsApplication::errorOccurred() const
+{
+ return (m_last_error_line != -1);
+}
+
+int pgsApplication::errorLine() const
+{
+ return m_last_error_line;
+}
if (m_app != 0)
{
m_app->LockOutput();
+ m_app->last_error_line(current->line());
}
m_cout << wx_static_cast(const wxString, e.message())
if (m_app != 0)
{
m_app->LockOutput();
+ m_app->last_error_line(current->line());
}
m_cout << PGSOUTERROR << _("Unknown exception:\n")
{
std::ostringstream oss;
oss << l;
+ thread.last_error_line(l.begin.line);
thread.LockOutput();
context.m_cout << wx_static_cast(const wxString, wxString(oss.str()
.c_str(), wxConvUTF8)) << wxT(": ") << m << wxT("\n");
pgsApplication & app, wxMBConv * conv) :
wxThread(wxTHREAD_DETACHED), m_vars(vars), m_mutex(mutex),
m_connection(connection), m_data(file), m_out(out),
- m_app(app), m_conv(conv)
+ m_app(app), m_conv(conv), m_last_error_line(-1)
{
wxLogScript(wxT("Starting thread"));
m_mutex.Wait();
pgsApplication & app) :
wxThread(wxTHREAD_DETACHED), m_vars(vars), m_mutex(mutex),
m_connection(connection), m_data(string), m_out(out),
- m_app(app), m_conv(0)
+ m_app(app), m_conv(0), m_last_error_line(-1)
{
wxLogScript(wxT("Starting thread"));
m_mutex.Wait();
{
m_app.UnlockOutput();
}
+
+void pgsThread::last_error_line(int line)
+{
+ m_last_error_line = line;
+}
+
+int pgsThread::last_error_line() const
+{
+ return m_last_error_line;
+}