56
65
#include "images/edit_undo.xpm"
57
66
#include "images/edit_redo.xpm"
58
67
#include "images/query_execute.xpm"
68
#include "images/query_pgscript.xpm"
59
69
#include "images/query_execfile.xpm"
60
70
#include "images/query_explain.xpm"
61
71
#include "images/query_cancel.xpm"
62
72
#include "images/help.xpm"
73
#include "images/gqbJoin.xpm"
65
75
#define CTRLID_CONNECTION 4200
66
76
#define CTRLID_DATABASELABEL 4201
78
// Initialize execution 'mutex'. As this will always run in the
79
// main thread, there aren't any real concurrency issues, so
80
// a simple flag will suffice.
81
// Required because the pgScript parser isn't currently thread-safe :-(
82
bool frmQuery::ms_pgScriptRunning = false;
68
84
BEGIN_EVENT_TABLE(frmQuery, pgFrame)
69
EVT_ERASE_BACKGROUND( frmQuery::OnEraseBackground)
70
EVT_SIZE( frmQuery::OnSize)
71
EVT_COMBOBOX(CTRLID_CONNECTION, frmQuery::OnChangeConnection)
72
EVT_CLOSE( frmQuery::OnClose)
73
EVT_SET_FOCUS( frmQuery::OnSetFocus)
74
EVT_MENU(MNU_NEW, frmQuery::OnNew)
75
EVT_MENU(MNU_OPEN, frmQuery::OnOpen)
76
EVT_MENU(MNU_SAVE, frmQuery::OnSave)
77
EVT_MENU(MNU_SAVEAS, frmQuery::OnSaveAs)
78
EVT_MENU(MNU_EXPORT, frmQuery::OnExport)
79
EVT_MENU(MNU_EXIT, frmQuery::OnExit)
80
EVT_MENU(MNU_CUT, frmQuery::OnCut)
81
EVT_MENU(MNU_COPY, frmQuery::OnCopy)
82
EVT_MENU(MNU_PASTE, frmQuery::OnPaste)
83
EVT_MENU(MNU_CLEAR, frmQuery::OnClear)
84
EVT_MENU(MNU_FIND, frmQuery::OnSearchReplace)
85
EVT_MENU(MNU_UNDO, frmQuery::OnUndo)
86
EVT_MENU(MNU_REDO, frmQuery::OnRedo)
87
EVT_MENU(MNU_EXECUTE, frmQuery::OnExecute)
88
EVT_MENU(MNU_EXECFILE, frmQuery::OnExecFile)
89
EVT_MENU(MNU_EXPLAIN, frmQuery::OnExplain)
90
EVT_MENU(MNU_CANCEL, frmQuery::OnCancel)
91
EVT_MENU(MNU_CONTENTS, frmQuery::OnContents)
92
EVT_MENU(MNU_HELP, frmQuery::OnHelp)
93
EVT_MENU(MNU_CLEARHISTORY, frmQuery::OnClearHistory)
94
EVT_MENU(MNU_SAVEHISTORY, frmQuery::OnSaveHistory)
95
EVT_MENU(MNU_SELECTALL, frmQuery::OnSelectAll)
96
EVT_MENU(MNU_QUICKREPORT, frmQuery::OnQuickReport)
97
EVT_MENU(MNU_AUTOINDENT, frmQuery::OnAutoIndent)
98
EVT_MENU(MNU_WORDWRAP, frmQuery::OnWordWrap)
99
EVT_MENU(MNU_SHOWINDENTGUIDES, frmQuery::OnShowIndentGuides)
100
EVT_MENU(MNU_SHOWWHITESPACE, frmQuery::OnShowWhitespace)
101
EVT_MENU(MNU_SHOWLINEENDS, frmQuery::OnShowLineEnds)
102
EVT_MENU(MNU_FAVOURITES_ADD, frmQuery::OnAddFavourite)
103
EVT_MENU(MNU_FAVOURITES_MANAGE, frmQuery::OnManageFavourites)
104
EVT_MENU(MNU_MACROS_MANAGE, frmQuery::OnMacroManage)
105
EVT_MENU(MNU_DATABASEBAR, frmQuery::OnToggleDatabaseBar)
106
EVT_MENU(MNU_TOOLBAR, frmQuery::OnToggleToolBar)
107
EVT_MENU(MNU_SCRATCHPAD, frmQuery::OnToggleScratchPad)
108
EVT_MENU(MNU_OUTPUTPANE, frmQuery::OnToggleOutputPane)
109
EVT_MENU(MNU_DEFAULTVIEW, frmQuery::OnDefaultView)
110
EVT_MENU(MNU_LF, frmQuery::OnSetEOLMode)
111
EVT_MENU(MNU_CRLF, frmQuery::OnSetEOLMode)
112
EVT_MENU(MNU_CR, frmQuery::OnSetEOLMode)
113
EVT_MENU_RANGE(MNU_FAVOURITES_MANAGE+1, MNU_FAVOURITES_MANAGE+999, frmQuery::OnSelectFavourite)
114
EVT_MENU_RANGE(MNU_MACROS_MANAGE+1, MNU_MACROS_MANAGE+99, frmQuery::OnMacroInvoke)
115
EVT_ACTIVATE( frmQuery::OnActivate)
116
EVT_STC_MODIFIED(CTL_SQLQUERY, frmQuery::OnChangeStc)
117
EVT_STC_UPDATEUI(CTL_SQLQUERY, frmQuery::OnPositionStc)
118
EVT_AUI_PANE_CLOSE( frmQuery::OnAuiUpdate)
120
EVT_TIMER(wxID_ANY, frmQuery::OnTimer)
122
// These fire when the queries complete
123
EVT_MENU(QUERY_COMPLETE, frmQuery::OnQueryComplete)
85
EVT_ERASE_BACKGROUND( frmQuery::OnEraseBackground)
86
EVT_SIZE( frmQuery::OnSize)
87
EVT_COMBOBOX(CTRLID_CONNECTION, frmQuery::OnChangeConnection)
88
EVT_CLOSE( frmQuery::OnClose)
89
EVT_SET_FOCUS( frmQuery::OnSetFocus)
90
EVT_MENU(MNU_NEW, frmQuery::OnNew)
91
EVT_MENU(MNU_OPEN, frmQuery::OnOpen)
92
EVT_MENU(MNU_SAVE, frmQuery::OnSave)
93
EVT_MENU(MNU_SAVEAS, frmQuery::OnSaveAs)
94
EVT_MENU(MNU_EXPORT, frmQuery::OnExport)
95
EVT_MENU(MNU_EXIT, frmQuery::OnExit)
96
EVT_MENU(MNU_CUT, frmQuery::OnCut)
97
EVT_MENU(MNU_COPY, frmQuery::OnCopy)
98
EVT_MENU(MNU_PASTE, frmQuery::OnPaste)
99
EVT_MENU(MNU_CLEAR, frmQuery::OnClear)
100
EVT_MENU(MNU_FIND, frmQuery::OnSearchReplace)
101
EVT_MENU(MNU_UNDO, frmQuery::OnUndo)
102
EVT_MENU(MNU_REDO, frmQuery::OnRedo)
103
EVT_MENU(MNU_EXECUTE, frmQuery::OnExecute)
104
EVT_MENU(MNU_EXECPGS, frmQuery::OnExecScript)
105
EVT_MENU(MNU_EXECFILE, frmQuery::OnExecFile)
106
EVT_MENU(MNU_EXPLAIN, frmQuery::OnExplain)
107
EVT_MENU(MNU_CANCEL, frmQuery::OnCancel)
108
EVT_MENU(MNU_CONTENTS, frmQuery::OnContents)
109
EVT_MENU(MNU_HELP, frmQuery::OnHelp)
110
EVT_MENU(MNU_CLEARHISTORY, frmQuery::OnClearHistory)
111
EVT_MENU(MNU_SAVEHISTORY, frmQuery::OnSaveHistory)
112
EVT_MENU(MNU_SELECTALL, frmQuery::OnSelectAll)
113
EVT_MENU(MNU_QUICKREPORT, frmQuery::OnQuickReport)
114
EVT_MENU(MNU_AUTOINDENT, frmQuery::OnAutoIndent)
115
EVT_MENU(MNU_WORDWRAP, frmQuery::OnWordWrap)
116
EVT_MENU(MNU_SHOWINDENTGUIDES, frmQuery::OnShowIndentGuides)
117
EVT_MENU(MNU_SHOWWHITESPACE, frmQuery::OnShowWhitespace)
118
EVT_MENU(MNU_SHOWLINEENDS, frmQuery::OnShowLineEnds)
119
EVT_MENU(MNU_FAVOURITES_ADD, frmQuery::OnAddFavourite)
120
EVT_MENU(MNU_FAVOURITES_MANAGE, frmQuery::OnManageFavourites)
121
EVT_MENU(MNU_MACROS_MANAGE, frmQuery::OnMacroManage)
122
EVT_MENU(MNU_DATABASEBAR, frmQuery::OnToggleDatabaseBar)
123
EVT_MENU(MNU_TOOLBAR, frmQuery::OnToggleToolBar)
124
EVT_MENU(MNU_SCRATCHPAD, frmQuery::OnToggleScratchPad)
125
EVT_MENU(MNU_OUTPUTPANE, frmQuery::OnToggleOutputPane)
126
EVT_MENU(MNU_DEFAULTVIEW, frmQuery::OnDefaultView)
127
EVT_MENU(MNU_BLOCK_INDENT, frmQuery::OnBlockIndent)
128
EVT_MENU(MNU_BLOCK_OUTDENT, frmQuery::OnBlockOutDent)
129
EVT_MENU(MNU_UPPER_CASE, frmQuery::OnChangeToUpperCase)
130
EVT_MENU(MNU_LOWER_CASE, frmQuery::OnChangeToLowerCase)
131
EVT_MENU(MNU_COMMENT_TEXT, frmQuery::OnCommentText)
132
EVT_MENU(MNU_UNCOMMENT_TEXT, frmQuery::OnUncommentText)
133
EVT_MENU(MNU_LF, frmQuery::OnSetEOLMode)
134
EVT_MENU(MNU_CRLF, frmQuery::OnSetEOLMode)
135
EVT_MENU(MNU_CR, frmQuery::OnSetEOLMode)
136
EVT_MENU_RANGE(MNU_FAVOURITES_MANAGE+1, MNU_FAVOURITES_MANAGE+999, frmQuery::OnSelectFavourite)
137
EVT_MENU_RANGE(MNU_MACROS_MANAGE+1, MNU_MACROS_MANAGE+99, frmQuery::OnMacroInvoke)
138
EVT_ACTIVATE( frmQuery::OnActivate)
139
EVT_STC_MODIFIED(CTL_SQLQUERY, frmQuery::OnChangeStc)
140
EVT_STC_UPDATEUI(CTL_SQLQUERY, frmQuery::OnPositionStc)
141
EVT_AUI_PANE_CLOSE( frmQuery::OnAuiUpdate)
142
EVT_TIMER(CTL_TIMERSIZES, frmQuery::OnAdjustSizesTimer)
143
EVT_TIMER(CTL_TIMERFRM, frmQuery::OnTimer)
144
// These fire when the queries complete
145
EVT_MENU(QUERY_COMPLETE, frmQuery::OnQueryComplete)
146
EVT_MENU(PGSCRIPT_COMPLETE, frmQuery::OnScriptComplete)
147
EVT_NOTEBOOK_PAGE_CHANGED(CTL_NTBKCENTER, frmQuery::OnChangeNotebook)
148
EVT_SPLITTER_SASH_POS_CHANGED(GQB_HORZ_SASH, frmQuery::OnResizeHorizontally)
124
149
END_EVENT_TABLE()
126
151
frmQuery::frmQuery(frmMain *form, const wxString& _title, pgConn *_conn, const wxString& query, const wxString& file)
127
152
: pgFrame(NULL, _title),
153
timer(this,CTL_TIMERFRM),
154
pgScript(new pgsApplication(_conn)),
155
pgsStringOutput(&pgsOutputString),
156
pgsOutput(pgsStringOutput, wxEOL_UNIX),
157
pgsTimer(new pgScriptTimer(this))
159
pgScript->SetCaller(this, PGSCRIPT_COMPLETE);
136
167
dlgName = wxT("frmQuery");
179
210
editMenu->Append(MNU_FIND, _("&Find and Replace\tCtrl-F"), _("Find and replace text"), wxITEM_NORMAL);
180
211
editMenu->AppendSeparator();
181
212
editMenu->Append(MNU_AUTOINDENT, _("&Auto indent"), _("Automatically indent text to the same level as the preceding line"), wxITEM_CHECK);
214
// editMenu->AppendSeparator();
215
formatMenu = new wxMenu();
216
formatMenu->Append(MNU_UPPER_CASE, _("&Upper case\tCtrl-U"), _("Change the selected text to upper case"));
217
formatMenu->Append(MNU_LOWER_CASE, _("&Lower case\tCtrl-Shift-U"), _("Change the selected text to lower case"));
218
formatMenu->AppendSeparator();
219
formatMenu->Append(MNU_BLOCK_INDENT, _("Block &Indent\tTab"), _("Indent the selected block"));
220
formatMenu->Append(MNU_BLOCK_OUTDENT, _("Block &Outdent\tShift-Tab"), _("Outdent the selected block"));
221
formatMenu->Append(MNU_COMMENT_TEXT, _("Co&mment Text\tCtrl-K"), _("Comment out the selected text"));
222
formatMenu->Append(MNU_UNCOMMENT_TEXT, _("Uncomme&nt Text\tCtrl-Shift-K"), _("Uncomment the selected text"));
223
editMenu->AppendSubMenu(formatMenu, _("F&ormat"));
182
224
editMenu->Append(MNU_LINEENDS, _("&Line ends"), lineEndMenu);
183
226
menuBar->Append(editMenu, _("&Edit"));
185
228
queryMenu = new wxMenu();
186
229
queryMenu->Append(MNU_EXECUTE, _("&Execute\tF5"), _("Execute query"));
230
queryMenu->Append(MNU_EXECPGS, _("Execute &pgScript\tF6"), _("Execute pgScript"));
187
231
queryMenu->Append(MNU_EXECFILE, _("Execute to file"), _("Execute query, write result to file"));
188
232
queryMenu->Append(MNU_EXPLAIN, _("E&xplain\tF7"), _("Explain query"));
190
235
wxMenu *eo=new wxMenu();
191
236
eo->Append(MNU_VERBOSE, _("Verbose"), _("Explain verbose query"), wxITEM_CHECK);
300
347
cbConnection->Append(conn->GetName(), (void*)conn);
301
348
cbConnection->Append(_("<new connection>"), (void*)0);
350
//Create SQL editor notebook
351
sqlNotebook = new wxNotebook(this, CTL_NTBKCENTER, wxDefaultPosition, wxDefaultSize);
304
sqlQuery = new ctlSQLBox(this, CTL_SQLQUERY, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxSIMPLE_BORDER | wxTE_RICH2);
354
sqlQuery = new ctlSQLBox(sqlNotebook, CTL_SQLQUERY, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxSIMPLE_BORDER | wxTE_RICH2);
305
355
sqlQuery->SetDatabase(conn);
306
356
sqlQuery->SetMarginWidth(1, 16);
307
SetLineEndingStyle();
357
SetEOLModeDisplay(sqlQuery->GetEOLMode());
310
outputPane = new wxNotebook(this, -1, wxDefaultPosition, wxSize(500, 300));
360
outputPane = new wxNotebook(this, CTL_NTBKGQB, wxDefaultPosition, wxSize(500, 300));
311
361
sqlResult = new ctlSQLResult(outputPane, conn, CTL_SQLRESULT, wxDefaultPosition, wxDefaultSize);
312
362
explainCanvas = new ExplainCanvas(outputPane);
313
363
msgResult = new wxTextCtrl(outputPane, CTL_MSGRESULT, wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY|wxTE_DONTWRAP);
314
364
msgResult->SetFont(settings->GetSQLFont());
315
365
msgHistory = new wxTextCtrl(outputPane, CTL_MSGHISTORY, wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY|wxTE_DONTWRAP);
316
366
msgHistory->SetFont(settings->GetSQLFont());
370
model=new gqbModel();
371
controller = new gqbController(model,sqlNotebook, outputPane, wxSize(1280,800));
372
firstTime=true; // Inform to GQB that the tree of table haven't filled.
373
gqbUpdateRunning = false; // Are we already updating the SQL query - event recursion protection.
374
adjustSizesTimer=NULL; // Timer used to avoid a bug when close outputPane
376
// Setup SQL editor notebook NBP_SQLEDTR
377
sqlNotebook->AddPage(sqlQuery, _("SQL Editor"));
378
sqlNotebook->AddPage(controller->getViewContainer(), _("Graphical Query Builder"));
379
sqlNotebook->SetSelection(0);
317
381
outputPane->AddPage(sqlResult, _("Data Output"));
318
382
outputPane->AddPage(explainCanvas, _("Explain"));
319
383
outputPane->AddPage(msgResult, _("Messages"));
1534
1777
execQuery(sql, resultToRetrieve, true, offset, false, true, verbose);
1780
// Update the main SQL query from the GQB if desired
1781
bool frmQuery::updateFromGqb(bool executing)
1786
// Make sure this doesn't get call recursively through an event
1787
if (gqbUpdateRunning)
1790
gqbUpdateRunning = true;
1792
// Execute Generation of SQL sentence from GQB
1793
bool canGenerate=false;
1794
wxString newQuery = controller->generateSQL();
1796
// If the new query is empty, don't do anything
1797
if (newQuery.IsEmpty())
1799
wxMessageBox(_("No SQL query was generated."), wxT("Graphical Query Builder"), wxICON_INFORMATION);
1800
gqbUpdateRunning = false;
1804
// Only prompt the user if the dirty flag is set, and the textbox is not empty, and the query has changed.
1805
if(changed && !sqlQuery->GetText().Trim().IsEmpty() && sqlQuery->GetText() != newQuery + wxT("\n"))
1809
fn = _("The generated SQL query has changed.\nDo you want to update it and execute the query?");
1811
fn = _("The generated SQL query has changed.\nDo you want to update it?");
1813
wxMessageDialog msg(this, fn, _("Query"), wxYES_NO|wxICON_EXCLAMATION);
1814
if(msg.ShowModal() == wxID_YES && changed)
1820
gqbUpdateRunning = false;
1830
sqlQuery->ClearAll();
1831
sqlQuery->AddText(newQuery + wxT("\n"));
1832
sqlQuery->Colourise(0, sqlQuery->GetText().Length());
1833
sqlNotebook->SetSelection(0);
1836
gqbUpdateRunning = false;
1537
1843
void frmQuery::OnExecute(wxCommandEvent& event)
1845
if(sqlNotebook->GetSelection()==1)
1847
if (!updateFromGqb(true))
1539
1851
wxString query=sqlQuery->GetSelectedText();
1540
1852
if (query.IsNull())
1541
1853
query = sqlQuery->GetText();
1543
1855
if (query.IsNull())
1545
1858
execQuery(query);
1546
1859
sqlQuery->SetFocus();
1863
void frmQuery::OnExecScript(wxCommandEvent& event)
1866
wxString query = sqlQuery->GetSelectedText();
1868
query = sqlQuery->GetText();
1872
// Make sure pgScript is not already running
1873
// Required because the pgScript parser isn't currently thread-safe :-(
1874
if (frmQuery::ms_pgScriptRunning == true)
1876
wxMessageBox(_("pgScript already running."), _("Concurrent execution of pgScripts is not supported at this time."), wxICON_WARNING);
1879
frmQuery::ms_pgScriptRunning = true;
1881
// Clear markers and indicators
1882
sqlQuery->MarkerDeleteAll(0);
1883
sqlQuery->StartStyling(0, wxSTC_INDICS_MASK);
1884
sqlQuery->SetStyling(sqlQuery->GetText().Length(), 0);
1886
// Menu stuff to initialize
1888
queryMenu->Enable(MNU_SAVEHISTORY, true);
1889
queryMenu->Enable(MNU_CLEARHISTORY, true);
1892
explainCanvas->Clear();
1894
outputPane->SetSelection(2);
1897
SetStatusText(wxT(""), STATUSPOS_SECS);
1898
SetStatusText(_("pgScript is running."), STATUSPOS_MSGS);
1899
SetStatusText(wxT(""), STATUSPOS_ROWS);
1902
msgHistory->AppendText(_("-- Executing pgScript\n"));
1904
wxTheApp->Yield(true);
1907
startTimeQuery = wxGetLocalTimeMillis();
1910
// Delete previous variables
1911
pgScript->ClearSymbols();
1913
// Parse script. Note that we add \n so the parse can correctly identify
1914
// a comment on the last line of the query.
1915
pgScript->ParseString(query + wxT("\n"), pgsOutput);
1916
pgsTimer->Start(20);
1550
1922
void frmQuery::OnExecFile(wxCommandEvent &event)
1924
if(sqlNotebook->GetSelection()==1)
1926
if (!updateFromGqb(true))
1552
1930
wxString query=sqlQuery->GetSelectedText();
1553
1931
if (query.IsNull())
1554
1932
query = sqlQuery->GetText();
1556
1934
if (query.IsNull())
1558
1937
execQuery(query, 0, false, 0, true);
1559
1938
sqlQuery->SetFocus();
1562
1942
void frmQuery::OnMacroManage(wxCommandEvent &event)
1564
int r = dlgManageMacros(this,mainForm,macros).ManageMacros();
1944
int r = dlgManageMacros(this,mainForm,macros).ManageMacros();
1567
/* Changed something, so save */
1947
// Changed something, so save
1568
1948
queryMacroFileProvider::SaveMacros(macros);
1569
1949
UpdateMacrosList();
1571
1951
else if (r == -1)
1573
/* Changed something requiring rollback */
1953
// Changed something requiring rollback
1575
1955
macros = queryMacroFileProvider::LoadMacros(true);
1576
1956
UpdateMacrosList();
1589
wxString query = mac->GetQuery();
1590
if (query.IsEmpty())
1591
return; // do not execute empty query
1970
wxString query = mac->GetQuery();
1971
if (query.IsEmpty())
1972
return; // do not execute empty query
1593
if (query.Find(wxT("$SELECTION$")) != wxNOT_FOUND)
1595
wxString selection = sqlQuery->GetSelectedText();
1596
if (selection.IsEmpty())
1598
wxMessageBox(_("This macro includes a text substitution. Please select some text in the SQL pane and re-run the macro."), _("Execute macro"), wxICON_EXCLAMATION);
1601
query.Replace(wxT("$SELECTION$"), selection);
1974
if (query.Find(wxT("$SELECTION$")) != wxNOT_FOUND)
1976
wxString selection = sqlQuery->GetSelectedText();
1977
if (selection.IsEmpty())
1979
wxMessageBox(_("This macro includes a text substitution. Please select some text in the SQL pane and re-run the macro."), _("Execute macro"), wxICON_EXCLAMATION);
1982
query.Replace(wxT("$SELECTION$"), selection);
1603
1984
execQuery(query);
1604
1985
sqlQuery->SetFocus();
1607
1989
void frmQuery::setTools(const bool running)
1609
1991
toolBar->EnableTool(MNU_EXECUTE, !running);
1992
toolBar->EnableTool(MNU_EXECPGS, !running);
1610
1993
toolBar->EnableTool(MNU_EXECFILE, !running);
1611
1994
toolBar->EnableTool(MNU_EXPLAIN, !running);
1612
1995
toolBar->EnableTool(MNU_CANCEL, running);
1613
1996
queryMenu->Enable(MNU_EXECUTE, !running);
1997
queryMenu->Enable(MNU_EXECPGS, !running);
1614
1998
queryMenu->Enable(MNU_EXECFILE, !running);
1615
1999
queryMenu->Enable(MNU_EXPLAIN, !running);
1616
2000
queryMenu->Enable(MNU_CANCEL, running);
1617
2001
fileMenu->Enable(MNU_EXPORT, sqlResult->CanExport());
1618
2002
fileMenu->Enable(MNU_QUICKREPORT, sqlResult->CanExport());
1619
2003
fileMenu->Enable(MNU_RECENT, (recentFileMenu->GetMenuItemCount() > 0));
2004
sqlQuery->EnableAutoComp(running);
1815
2212
sqlResult->DisplayData(true);
1817
showMessage(wxString::Format(_("%d rows retrieved."), sqlResult->NumRows()), _("OK."));
2214
showMessage(wxString::Format(
2215
wxPLURAL("%d row retrieved.", "%d rows retrieved.", sqlResult->NumRows()),
2216
sqlResult->NumRows()), _("OK."));
1821
SetStatusText(wxString::Format(_("Retrieving data: %d rows."), rowsTotal), STATUSPOS_MSGS);
2220
SetStatusText(wxString::Format(wxPLURAL("Retrieving data: %d row.", "Retrieving data: %d rows.", rowsTotal), rowsTotal), STATUSPOS_MSGS);
1822
2221
wxTheApp->Yield(true);
1824
2223
sqlResult->DisplayData();
1828
2225
SetStatusText(elapsedQuery.ToString() + wxT(" ms"), STATUSPOS_SECS);
1830
2227
str= _("Total query runtime: ") + elapsedQuery.ToString() + wxT(" ms.\n") ;
1831
2228
msgResult->AppendText(str);
1832
2229
msgHistory->AppendText(str);
1834
showMessage(wxString::Format(_("%ld rows retrieved."), sqlResult->NumRows()), _("OK."));
2231
showMessage(wxString::Format(wxPLURAL("%ld row retrieved.", "%ld rows retrieved.", sqlResult->NumRows()), sqlResult->NumRows()), _("OK."));
1836
SetStatusText(wxString::Format(_("%d rows."), rowsTotal), STATUSPOS_ROWS);
2233
SetStatusText(wxString::Format(wxPLURAL("%d row.", "%d rows.", rowsTotal), rowsTotal), STATUSPOS_ROWS);
1840
2237
completeQuery(done, qi->explain, qi->verbose);
2241
void frmQuery::OnScriptComplete(wxCommandEvent &ev)
2248
writeScriptOutput();
2253
// Unlock our pseudo-mutex thingy
2254
frmQuery::ms_pgScriptRunning = false;
2257
elapsedQuery = wxGetLocalTimeMillis() - startTimeQuery;
2258
SetStatusText(elapsedQuery.ToString() + wxT(" ms"), STATUSPOS_SECS);
2259
SetStatusText(_("pgScript completed."), STATUSPOS_MSGS);
2260
wxString str = _("Total pgScript runtime: ") + elapsedQuery.ToString() + wxT(" ms.\n\n");
2261
msgHistory->AppendText(str);
2263
// Check whether there was an error/exception
2264
if (pgScript->errorOccurred() && pgScript->errorLine() >= 1)
2266
// Find out what the line number is
2267
int selStart = sqlQuery->GetSelectionStart(), selEnd = sqlQuery->GetSelectionEnd();
2268
if (selStart == selEnd)
2270
int line = 0, maxLine = sqlQuery->GetLineCount();
2271
while (line < maxLine && sqlQuery->GetLineEndPosition(line) < selStart)
2273
line += pgScript->errorLine() - 1;
2275
// Mark the line where the error occurred
2276
sqlQuery->MarkerAdd(line, 0);
2279
sqlQuery->GotoPos(sqlQuery->GetLineEndPosition(line));
2283
void frmQuery::writeScriptOutput()
2285
pgScript->LockOutput();
2287
wxString output(pgsOutputString);
2288
pgsOutputString.Clear();
2289
msgResult->AppendText(output);
2291
pgScript->UnlockOutput();
1843
2294
// Complete the processing of a query
1844
2295
void frmQuery::completeQuery(bool done, bool explain, bool verbose)
2400
// Adjust sizes of GQB components, Located here because need to
2401
// avoid some issues when implementing inside controller/view Classes
2402
void frmQuery::adjustGQBSizes()
2404
// Get Size (only height) from main Tab with GQB and SQL Editor and adjust the width
2405
// to desiree, then set [Sash of tablesBrowser | GQB_Canvas]
2407
sqlNotebook->Refresh();
2408
wxSize s = sqlNotebook->GetSize();
2410
s.SetHeight(s.GetHeight()-180); //re-adjust weight eliminating Horz Sash Position
2411
controller->getTablesBrowser()->SetSize(s);
2412
controller->setSashVertPosition(controller->getTablesBrowser()->GetSize().GetWidth());
2414
// Now Adjust Sash Horizontal
2415
s = sqlNotebook->GetSize();
2416
controller->setSashHorizPosition(s.GetHeight()-150);
2418
// Adjust GQB grids internal columns sizes
2419
controller->calcGridColsSizes();
2423
// Adjust sizes of GQB components after vertical sash adjustment,
2424
// Located here because need to avoid some issues when implementing
2425
// inside controller/view Classes
2426
void frmQuery::OnResizeHorizontally(wxSplitterEvent& event)
2428
int y = event.GetSashPosition();
2429
wxSize s = controller->getTablesBrowser()->GetSize();
2430
s.SetHeight(y); // re-adjust weight eliminating Horz Sash Position
2431
controller->getTablesBrowser()->SetSize(s);
2436
// This function adjust the GQB Components after an event on the wxAui
2437
// event, it's a workaround because need event finish to work properly
2438
void frmQuery::OnAdjustSizesTimer(wxTimerEvent & event)
2441
adjustSizesTimer->Stop();
2444
void frmQuery::OnBlockIndent(wxCommandEvent& event)
2446
sqlQuery->CmdKeyExecute(wxSTC_CMD_TAB);
2449
void frmQuery::OnBlockOutDent(wxCommandEvent& event)
2451
sqlQuery->CmdKeyExecute(wxSTC_CMD_BACKTAB);
2454
void frmQuery::OnChangeToUpperCase(wxCommandEvent& event)
2456
sqlQuery->UpperCase();
2459
void frmQuery::OnChangeToLowerCase(wxCommandEvent& event)
2461
sqlQuery->LowerCase();
2464
void frmQuery::OnCommentText(wxCommandEvent& event)
2466
sqlQuery->BlockComment(false);
2469
void frmQuery::OnUncommentText(wxCommandEvent& event)
2471
sqlQuery->BlockComment(true);
1946
2474
///////////////////////////////////////////////////////
1949
2476
wxWindow *queryToolBaseFactory::StartDialogSql(frmMain *form, pgObject *obj, const wxString &sql)
1951
2478
pgDatabase *db=obj->GetDatabase();