~ubuntu-branches/debian/sid/pgadmin3/sid

« back to all changes in this revision

Viewing changes to pgadmin/frm/frmQuery.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gerfried Fuchs
  • Date: 2009-07-30 12:27:16 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090730122716-fddbh42on721bbs2
Tags: 1.10.0-1
* New upstream release.
* Adjusted watch file to match release candidates.
* Updated to Standards-Version 3.8.2:
  - Moved to Section: database.
  - Add DEB_BUILD_OPTIONS support for parallel building.
  - Move from findstring to filter suggestion for DEB_BUILD_OPTIONS parsing.
* pgagent got split into its own separate source package by upstream.
* Exclude Docs.vcproj from installation.
* Move doc-base.enus from pgadmin3 to pgadmin3-data package, the files are
  in there too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//////////////////////////////////////////////////////////////////////////
2
2
//
3
3
// pgAdmin III - PostgreSQL Tools
4
 
// RCS-ID:      $Id: frmQuery.cpp 7353 2008-06-04 08:07:22Z dpage $
5
 
// Copyright (C) 2002 - 2008, The pgAdmin Development Team
6
 
// This software is released under the Artistic Licence
 
4
// RCS-ID:      $Id: frmQuery.cpp 7945 2009-06-26 09:00:11Z dpage $
 
5
// Copyright (C) 2002 - 2009, The pgAdmin Development Team
 
6
// This software is released under the BSD Licence
7
7
//
8
8
// frmQuery.cpp - SQL Query Box
9
9
//
13
13
 
14
14
// wxWindows headers
15
15
#include <wx/wx.h>
 
16
#include <wx/busyinfo.h>
 
17
#include <wx/clipbrd.h>
 
18
#include <wx/dcbuffer.h>
 
19
#include <wx/filename.h>
16
20
#include <wx/regex.h>
17
 
#include <wx/filename.h>
 
21
#include <wx/textctrl.h>
18
22
#include <wx/timer.h>
19
 
 
20
 
// wxAUI
21
23
#include <wx/aui/aui.h>
22
24
 
23
25
// App headers
27
29
#include "ctl/explainCanvas.h"
28
30
#include "db/pgConn.h"
29
31
 
 
32
#include "ctl/ctlMenuToolbar.h"
30
33
#include "ctl/ctlSQLResult.h"
31
 
#include "schema/pgDatabase.h"
32
 
#include "schema/pgTable.h"
33
 
#include "schema/pgView.h"
34
34
#include "dlg/dlgSelectConnection.h"
35
35
#include "dlg/dlgAddFavourite.h"
36
36
#include "dlg/dlgManageFavourites.h"
37
37
#include "dlg/dlgManageMacros.h"
 
38
#include "frm/frmReport.h"
 
39
#include "gqb/gqbViewController.h"
 
40
#include "gqb/gqbModel.h"
 
41
#include "gqb/gqbViewPanels.h"
 
42
#include "gqb/gqbEvents.h"
 
43
#include "schema/pgDatabase.h"
 
44
#include "schema/pgTable.h"
 
45
#include "schema/pgView.h"
 
46
#include "schema/gpExtTable.h"
 
47
#include "schema/pgServer.h"
38
48
#include "utils/favourites.h"
39
49
#include "utils/sysLogger.h"
40
50
#include "utils/utffile.h"
41
 
#include "frm/frmReport.h"
42
 
 
43
 
#include <wx/clipbrd.h>
 
51
#include "pgscript/pgsApplication.h"
44
52
 
45
53
// Icons
46
54
#include "images/sql.xpm"
 
55
 
47
56
// Bitmaps
48
57
#include "images/file_new.xpm"
49
58
#include "images/file_open.xpm"
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"
63
 
 
 
73
#include "images/gqbJoin.xpm"
64
74
 
65
75
#define CTRLID_CONNECTION       4200
66
76
#define CTRLID_DATABASELABEL    4201
67
77
 
 
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;
 
83
 
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)
119
 
 
120
 
    EVT_TIMER(wxID_ANY,             frmQuery::OnTimer)
121
 
 
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()
125
150
 
126
151
frmQuery::frmQuery(frmMain *form, const wxString& _title, pgConn *_conn, const wxString& query, const wxString& file)
127
152
: pgFrame(NULL, _title),
128
 
  timer(this)
 
153
timer(this,CTL_TIMERFRM),
 
154
pgScript(new pgsApplication(_conn)),
 
155
pgsStringOutput(&pgsOutputString),
 
156
pgsOutput(pgsStringOutput, wxEOL_UNIX),
 
157
pgsTimer(new pgScriptTimer(this))
129
158
{
 
159
    pgScript->SetCaller(this, PGSCRIPT_COMPLETE);
 
160
 
130
161
    mainForm=form;
131
162
    conn=_conn;
132
163
 
133
 
        loading = true;
 
164
    loading = true;
134
165
    closing = false;
135
166
 
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);
 
213
 
 
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);
 
225
 
183
226
    menuBar->Append(editMenu, _("&Edit"));
184
227
 
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"));
 
233
    
189
234
 
190
235
    wxMenu *eo=new wxMenu();
191
236
    eo->Append(MNU_VERBOSE, _("Verbose"), _("Explain verbose query"), wxITEM_CHECK);
206
251
    UpdateFavouritesList();
207
252
    menuBar->Append(favouritesMenu, _("Fav&ourites"));
208
253
 
209
 
        macrosMenu = new wxMenu();
210
 
        macrosMenu->Append(MNU_MACROS_MANAGE, _("Manage macros..."), _("Edit and delete macros"));
211
 
        macrosMenu->AppendSeparator();
212
 
        macros = queryMacroFileProvider::LoadMacros(true);
213
 
        UpdateMacrosList();
214
 
        menuBar->Append(macrosMenu, _("&Macros"));
 
254
    macrosMenu = new wxMenu();
 
255
    macrosMenu->Append(MNU_MACROS_MANAGE, _("Manage macros..."), _("Edit and delete macros"));
 
256
    macrosMenu->AppendSeparator();
 
257
    macros = queryMacroFileProvider::LoadMacros(true);
 
258
    UpdateMacrosList();
 
259
    menuBar->Append(macrosMenu, _("&Macros"));
215
260
 
216
261
    // View menu
217
262
    viewMenu = new wxMenu();
218
 
    viewMenu->Append(MNU_DATABASEBAR, _("&Database bar\tCtrl-Alt-D"), _("Show or hide the database selection bar."), wxITEM_CHECK);
 
263
    viewMenu->Append(MNU_DATABASEBAR, _("&Database bar\tCtrl-Alt-B"), _("Show or hide the database selection bar."), wxITEM_CHECK);
219
264
    viewMenu->Append(MNU_OUTPUTPANE, _("&Output pane\tCtrl-Alt-O"), _("Show or hide the output pane."), wxITEM_CHECK);
220
265
    viewMenu->Append(MNU_SCRATCHPAD, _("S&cratch pad\tCtrl-Alt-S"), _("Show or hide the scratch pad."), wxITEM_CHECK);
221
266
    viewMenu->Append(MNU_TOOLBAR, _("&Tool bar\tCtrl-Alt-T"), _("Show or hide the tool bar."), wxITEM_CHECK);
232
277
    wxMenu *helpMenu=new wxMenu();
233
278
    helpMenu->Append(MNU_CONTENTS, _("&Help"),                 _("Open the helpfile."));
234
279
    helpMenu->Append(MNU_HELP, _("&SQL Help\tF1"),                _("Display help on SQL commands."));
 
280
 
235
281
    menuBar->Append(helpMenu, _("&Help"));
236
282
 
237
 
 
238
283
    SetMenuBar(menuBar);
239
284
 
240
285
    queryMenu->Check(MNU_VERBOSE, settings->GetExplainVerbose());
242
287
 
243
288
    UpdateRecentFiles();
244
289
 
245
 
    wxAcceleratorEntry entries[11];
 
290
    wxAcceleratorEntry entries[12];
246
291
 
247
292
    entries[0].Set(wxACCEL_CTRL,                (int)'E',      MNU_EXECUTE);
248
293
    entries[1].Set(wxACCEL_CTRL,                (int)'O',      MNU_OPEN);
255
300
    entries[8].Set(wxACCEL_CTRL,                (int)'A',       MNU_SELECTALL);
256
301
    entries[9].Set(wxACCEL_NORMAL,              WXK_F1,        MNU_HELP);
257
302
    entries[10].Set(wxACCEL_CTRL,               (int)'N',      MNU_NEW);
 
303
    entries[11].Set(wxACCEL_CTRL,               WXK_F6,        MNU_EXECPGS);
258
304
 
259
 
    wxAcceleratorTable accel(11, entries);
 
305
    wxAcceleratorTable accel(12, entries);
260
306
    SetAcceleratorTable(accel);
261
307
 
262
308
    queryMenu->Enable(MNU_CANCEL, false);
267
313
    SetStatusWidths(6, iWidths);
268
314
    SetStatusText(_("ready"), STATUSPOS_MSGS);
269
315
 
270
 
    toolBar = new wxToolBar(this, -1, wxDefaultPosition, wxDefaultSize, wxTB_FLAT | wxTB_NODIVIDER);
 
316
    toolBar = new ctlMenuToolbar(this, -1, wxDefaultPosition, wxDefaultSize, wxTB_FLAT | wxTB_NODIVIDER);
271
317
 
272
318
    toolBar->SetToolBitmapSize(wxSize(16, 16));
273
319
 
287
333
    toolBar->AddSeparator();
288
334
 
289
335
    toolBar->AddTool(MNU_EXECUTE, _("Execute"), wxBitmap(query_execute_xpm), _("Execute query"), wxITEM_NORMAL);
 
336
    toolBar->AddTool(MNU_EXECPGS, _("Execute pgScript"), wxBitmap(query_pgscript_xpm), _("Execute pgScript"), wxITEM_NORMAL);
290
337
    toolBar->AddTool(MNU_EXECFILE, _("Execute to file"), wxBitmap(query_execfile_xpm), _("Execute query, write result to file"), wxITEM_NORMAL);
291
338
    toolBar->AddTool(MNU_EXPLAIN, _("Explain"), wxBitmap(query_explain_xpm), _("Explain query"), wxITEM_NORMAL);
292
339
    toolBar->AddTool(MNU_CANCEL, _("Cancel"), wxBitmap(query_cancel_xpm), _("Cancel query"), wxITEM_NORMAL);
300
347
    cbConnection->Append(conn->GetName(), (void*)conn);
301
348
    cbConnection->Append(_("<new connection>"), (void*)0);
302
349
 
 
350
    //Create SQL editor notebook
 
351
    sqlNotebook = new wxNotebook(this, CTL_NTBKCENTER, wxDefaultPosition, wxDefaultSize);
 
352
 
303
353
    // Query box
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());
308
358
 
309
359
    // Results pane
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());
 
367
 
 
368
    // Graphical Canvas
 
369
    // initialize values
 
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
 
375
 
 
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);
 
380
 
317
381
    outputPane->AddPage(sqlResult, _("Data Output"));
318
382
    outputPane->AddPage(explainCanvas, _("Explain"));
319
383
    outputPane->AddPage(msgResult, _("Messages"));
324
388
    msgResult->Connect(wxID_ANY, wxEVT_SET_FOCUS, wxFocusEventHandler(frmQuery::OnFocus));
325
389
    msgHistory->Connect(wxID_ANY, wxEVT_SET_FOCUS, wxFocusEventHandler(frmQuery::OnFocus));
326
390
 
327
 
    // Finally, the scratchpad
 
391
    // Now, the scratchpad
328
392
    scratchPad = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxHSCROLL);
329
393
 
330
394
    // Kickstart wxAUI
331
395
    manager.AddPane(toolBar, wxAuiPaneInfo().Name(wxT("toolBar")).Caption(_("Tool bar")).ToolbarPane().Top().LeftDockable(false).RightDockable(false));
332
396
    manager.AddPane(cbConnection, wxAuiPaneInfo().Name(wxT("databaseBar")).Caption(_("Database bar")).ToolbarPane().Top().LeftDockable(false).RightDockable(false));
333
 
    manager.AddPane(sqlQuery, wxAuiPaneInfo().Name(wxT("sqlQuery")).Caption(_("SQL query")).Center().CaptionVisible(false).CloseButton(false).MinSize(wxSize(200,100)).BestSize(wxSize(350,200)));
334
397
    manager.AddPane(outputPane, wxAuiPaneInfo().Name(wxT("outputPane")).Caption(_("Output pane")).Bottom().MinSize(wxSize(200,100)).BestSize(wxSize(550,300)));
335
398
    manager.AddPane(scratchPad, wxAuiPaneInfo().Name(wxT("scratchPad")).Caption(_("Scratch pad")).Right().MinSize(wxSize(100,100)).BestSize(wxSize(250,200)));
 
399
    manager.AddPane(sqlNotebook, wxAuiPaneInfo().Name(wxT("sqlQuery")).Caption(_("SQL query")).Center().CaptionVisible(false).CloseButton(false).MinSize(wxSize(200,100)).BestSize(wxSize(350,200)));
336
400
 
337
 
    // Now load the layout
338
 
    wxString perspective;
339
 
    settings->Read(wxT("frmQuery/Perspective-") + VerFromRev(FRMQUERY_PERPSECTIVE_VER), &perspective, FRMQUERY_DEFAULT_PERSPECTIVE);
 
401
    // Now load the layout    
 
402
    wxString perspective;    
 
403
    settings->Read(wxT("frmQuery/Perspective-") + VerFromRev(FRMQUERY_PERPSECTIVE_VER), &perspective, FRMQUERY_DEFAULT_PERSPECTIVE);    
340
404
    manager.LoadPerspective(perspective, true);
341
405
 
342
406
    // and reset the captions for the current language
346
410
    manager.GetPane(wxT("outputPane")).Caption(_("Output pane"));
347
411
    manager.GetPane(wxT("scratchPad")).Caption(_("Scratch pad"));
348
412
 
 
413
 
349
414
    // Sync the View menu options
350
415
    viewMenu->Check(MNU_DATABASEBAR, manager.GetPane(wxT("databaseBar")).IsShown());
351
416
    viewMenu->Check(MNU_TOOLBAR, manager.GetPane(wxT("toolBar")).IsShown());
379
444
    if (bVal)
380
445
        sqlQuery->SetIndentationGuides(true);
381
446
    else
382
 
        sqlQuery->SetIndentationGuides(false); 
 
447
        sqlQuery->SetIndentationGuides(false);
383
448
 
384
449
    // Whitespace
385
450
    settings->Read(wxT("frmQuery/ShowWhitespace"), &bVal, false);
387
452
    if (bVal)
388
453
        sqlQuery->SetViewWhiteSpace(wxSTC_WS_VISIBLEALWAYS);
389
454
    else
390
 
        sqlQuery->SetViewWhiteSpace(wxSTC_WS_INVISIBLE); 
 
455
        sqlQuery->SetViewWhiteSpace(wxSTC_WS_INVISIBLE);
391
456
 
392
457
    // Line ends
393
458
    settings->Read(wxT("frmQuery/ShowLineEnds"), &bVal, false);
403
468
        lastFilename=fn.GetFullName();
404
469
        lastDir = fn.GetPath();
405
470
        lastPath = fn.GetFullPath();
406
 
        OpenLastFile();    
 
471
        OpenLastFile();
407
472
    }
408
473
    else
409
474
        sqlQuery->SetText(query);
426
491
 
427
492
frmQuery::~frmQuery()
428
493
{
429
 
    sqlQuery->Disconnect(wxID_ANY, wxEVT_SET_FOCUS,wxFocusEventHandler(frmQuery::OnFocus));
430
 
    sqlResult->Disconnect(wxID_ANY, wxEVT_SET_FOCUS, wxFocusEventHandler(frmQuery::OnFocus));
431
 
    msgResult->Disconnect(wxID_ANY, wxEVT_SET_FOCUS, wxFocusEventHandler(frmQuery::OnFocus));
432
 
    msgHistory->Disconnect(wxID_ANY, wxEVT_SET_FOCUS, wxFocusEventHandler(frmQuery::OnFocus));
433
 
 
434
 
    if (mainForm)
435
 
        mainForm->RemoveFrame(this);
436
 
 
 
494
    closing = true;
 
495
 
 
496
    // Save frmQuery Perspective
437
497
    settings->Write(wxT("frmQuery/Perspective-") + VerFromRev(FRMQUERY_PERPSECTIVE_VER), manager.SavePerspective());
 
498
 
 
499
    // Uninitialize wxAUIManager
438
500
    manager.UnInit();
439
501
 
440
 
    settings->SetExplainAnalyze(queryMenu->IsChecked(MNU_ANALYZE));
441
 
    settings->SetExplainVerbose(queryMenu->IsChecked(MNU_VERBOSE));
442
 
 
443
 
    sqlResult->Abort(); // to make sure conn is unused
 
502
    if(sqlNotebook)
 
503
    {
 
504
        delete sqlNotebook;
 
505
        sqlNotebook = NULL;
 
506
    }
 
507
    if(controller)
 
508
    {
 
509
        delete controller;
 
510
        controller = NULL;
 
511
    }
 
512
    if(model)
 
513
    {
 
514
        delete model;
 
515
        model = NULL;
 
516
    }
 
517
    if(adjustSizesTimer)
 
518
    {
 
519
        delete adjustSizesTimer;
 
520
        adjustSizesTimer = NULL;
 
521
    }
444
522
 
445
523
    while (cbConnection->GetCount() > 1)
446
524
    {
449
527
    }
450
528
 
451
529
    if (favourites)
 
530
    {
452
531
        delete favourites;
 
532
        favourites = NULL;
 
533
    }
 
534
        
 
535
    if (pgsTimer)
 
536
    {
 
537
        delete pgsTimer;
 
538
        pgsTimer = NULL;
 
539
    }
 
540
 
 
541
    if (pgScript)
 
542
    {
 
543
        delete pgScript;
 
544
        pgScript = NULL;
 
545
    }
 
546
 
 
547
    if (mainForm)
 
548
        mainForm->RemoveFrame(this);
453
549
}
454
550
 
 
551
 
455
552
void frmQuery::OnExit(wxCommandEvent& event)
456
553
{
457
554
    closing = true;
458
555
    Close();
459
556
}
460
557
 
 
558
 
461
559
void frmQuery::OnEraseBackground(wxEraseEvent& event)
462
560
{
463
561
    event.Skip();
464
562
}
465
563
 
 
564
 
466
565
void frmQuery::OnSize(wxSizeEvent& event)
467
566
{
468
567
    event.Skip();
469
568
}
470
569
 
 
570
 
471
571
void frmQuery::OnToggleScratchPad(wxCommandEvent& event)
472
572
{
473
573
    if (viewMenu->IsChecked(MNU_SCRATCHPAD))
477
577
    manager.Update();
478
578
}
479
579
 
 
580
 
480
581
void frmQuery::OnToggleDatabaseBar(wxCommandEvent& event)
481
582
{
482
583
    if (viewMenu->IsChecked(MNU_DATABASEBAR))
486
587
    manager.Update();
487
588
}
488
589
 
 
590
 
489
591
void frmQuery::OnToggleToolBar(wxCommandEvent& event)
490
592
{
491
593
    if (viewMenu->IsChecked(MNU_TOOLBAR))
495
597
    manager.Update();
496
598
}
497
599
 
 
600
 
498
601
void frmQuery::OnToggleOutputPane(wxCommandEvent& event)
499
602
{
500
603
    if (viewMenu->IsChecked(MNU_OUTPUTPANE))
 
604
    {
501
605
        manager.GetPane(wxT("outputPane")).Show(true);
 
606
    }
502
607
    else
 
608
    {
503
609
        manager.GetPane(wxT("outputPane")).Show(false);
 
610
    }
504
611
    manager.Update();
 
612
    adjustGQBSizes();
505
613
}
506
614
 
 
615
 
507
616
void frmQuery::OnAuiUpdate(wxAuiManagerEvent& event)
508
617
{
509
618
    if(event.pane->name == wxT("databaseBar"))
517
626
    else if(event.pane->name == wxT("outputPane"))
518
627
    {
519
628
        viewMenu->Check(MNU_OUTPUTPANE, false);
 
629
        if(!adjustSizesTimer)
 
630
            adjustSizesTimer = new wxTimer(this,CTL_TIMERSIZES);
 
631
        adjustSizesTimer->Start(500);
520
632
    }
521
633
    else if(event.pane->name == wxT("scratchPad"))
522
634
    {
525
637
    event.Skip();
526
638
}
527
639
 
 
640
 
528
641
void frmQuery::OnDefaultView(wxCommandEvent& event)
529
642
{
530
643
    manager.LoadPerspective(FRMQUERY_DEFAULT_PERSPECTIVE, true);
545
658
    viewMenu->Check(MNU_SCRATCHPAD, manager.GetPane(wxT("scratchPad")).IsShown());
546
659
}
547
660
 
 
661
 
548
662
void frmQuery::OnAutoIndent(wxCommandEvent &event)
549
663
{
550
664
    editMenu->Check(MNU_AUTOINDENT, event.IsChecked());
551
665
 
552
666
    settings->Write(wxT("frmQuery/AutoIndent"), editMenu->IsChecked(MNU_AUTOINDENT));
553
 
    
 
667
 
554
668
    if (editMenu->IsChecked(MNU_AUTOINDENT))
555
669
        sqlQuery->SetAutoIndent(true);
556
670
    else
557
671
        sqlQuery->SetAutoIndent(false);
558
672
}
559
673
 
 
674
 
560
675
void frmQuery::OnWordWrap(wxCommandEvent &event)
561
676
{
562
677
    viewMenu->Check(MNU_WORDWRAP, event.IsChecked());
563
678
 
564
679
    settings->Write(wxT("frmQuery/WordWrap"), viewMenu->IsChecked(MNU_WORDWRAP));
565
 
    
 
680
 
566
681
    if (viewMenu->IsChecked(MNU_WORDWRAP))
567
682
        sqlQuery->SetWrapMode(wxSTC_WRAP_WORD);
568
683
    else
569
684
        sqlQuery->SetWrapMode(wxSTC_WRAP_NONE);
570
685
}
571
686
 
 
687
 
572
688
void frmQuery::OnShowIndentGuides(wxCommandEvent& event)
573
689
{
574
690
    viewMenu->Check(MNU_SHOWINDENTGUIDES, event.IsChecked());
575
691
 
576
692
    settings->Write(wxT("frmQuery/ShowIndentGuides"), viewMenu->IsChecked(MNU_SHOWINDENTGUIDES));
577
 
    
 
693
 
578
694
    if (viewMenu->IsChecked(MNU_SHOWINDENTGUIDES))
579
695
        sqlQuery->SetIndentationGuides(true);
580
696
    else
581
697
        sqlQuery->SetIndentationGuides(false);
582
698
}
583
699
 
 
700
 
584
701
void frmQuery::OnShowWhitespace(wxCommandEvent& event)
585
702
{
586
703
    viewMenu->Check(MNU_SHOWWHITESPACE, event.IsChecked());
587
704
 
588
705
    settings->Write(wxT("frmQuery/ShowWhitespace"), viewMenu->IsChecked(MNU_SHOWWHITESPACE));
589
 
    
 
706
 
590
707
    if (viewMenu->IsChecked(MNU_SHOWWHITESPACE))
591
708
        sqlQuery->SetViewWhiteSpace(wxSTC_WS_VISIBLEALWAYS);
592
709
    else
593
710
        sqlQuery->SetViewWhiteSpace(wxSTC_WS_INVISIBLE);
594
711
}
595
712
 
 
713
 
596
714
void frmQuery::OnShowLineEnds(wxCommandEvent& event)
597
715
{
598
716
    viewMenu->Check(MNU_SHOWLINEENDS, event.IsChecked());
599
717
 
600
718
    settings->Write(wxT("frmQuery/ShowLineEnds"), viewMenu->IsChecked(MNU_SHOWLINEENDS));
601
 
    
 
719
 
602
720
    if (viewMenu->IsChecked(MNU_SHOWLINEENDS))
603
721
        sqlQuery->SetViewEOL(1);
604
722
    else
628
746
 
629
747
    Show(true);
630
748
    sqlQuery->SetFocus();
631
 
        loading = false;
 
749
    loading = false;
632
750
}
633
751
 
634
752
 
635
753
typedef struct __sqltokenhelp
636
754
{
637
 
    wxChar *token;
638
 
    wxChar *page;
 
755
    const wxChar *token;
 
756
    const wxChar *page;
639
757
    int type;
640
758
} SqlTokenHelp;
641
759
 
642
 
 
643
760
SqlTokenHelp sqlTokenHelp[] =
644
761
{
645
762
    { wxT("ABORT"), 0, 0},
669
786
    { wxT("MOVE"), 0, 0},
670
787
    { wxT("NOTIFY"), 0, 0},
671
788
    { wxT("END"), 0, 0},
672
 
//    { wxT("PREPARE"), 0, 0},  handled individually
 
789
    // { wxT("PREPARE"), 0, 0},  handled individually
673
790
    { wxT("REINDEX"), 0, 0},
674
791
    { wxT("RELEASE"), wxT("pg/sql-release-savepoint"), 0},
675
792
    { wxT("RESET"), 0, 0},
676
793
    { wxT("REVOKE"), 0, 0},
677
 
//    { wxT("ROLLBACK"), 0, 0}, handled individually
 
794
    // { wxT("ROLLBACK"), 0, 0}, handled individually
678
795
    { wxT("SAVEPOINT"), 0, 0},
679
796
    { wxT("SELECT"), 0, 0},
680
797
    { wxT("SET"), 0, 0},
706
823
    { wxT("TYPE"), 0, 11},
707
824
    { wxT("USER"), 0, 12},
708
825
    { wxT("VIEW"), 0, 11},
 
826
    { wxT("EXTTABLE"), 0, 12},
709
827
    { 0, 0 }
710
828
};
711
829
 
712
 
 
713
830
void frmQuery::OnContents(wxCommandEvent& event)
714
831
{
715
832
    DisplayHelp(wxT("query"), HELP_PGADMIN);
720
837
{
721
838
    // On Solaris, this event seems to get fired when the form closes(!!)
722
839
    if(!IsVisible() && !loading)
723
 
        return; 
 
840
        return;
724
841
 
725
842
    unsigned int sel=cbConnection->GetCurrentSelection();
726
843
    if (sel == cbConnection->GetCount()-1)
759
876
        sqlResult->SetConnection(conn);
760
877
        title = wxT("Query - ") + cbConnection->GetValue();
761
878
        setExtendedTitle();
 
879
 
 
880
        //Refresh GQB Tree if used
 
881
        if(conn && !firstTime)
 
882
        {
 
883
            controller->getTablesBrowser()->refreshTables(conn);
 
884
            controller->getView()->Refresh();
 
885
        }
762
886
    }
763
887
}
764
888
 
835
959
 
836
960
    if (conn->GetIsEdb())
837
961
        DisplayHelp(page, HELP_ENTERPRISEDB);
 
962
    else if (conn->GetIsGreenplum())
 
963
        DisplayHelp(page, HELP_GREENPLUM);
838
964
    else
839
965
        DisplayHelp(page, HELP_POSTGRESQL);
840
966
}
842
968
 
843
969
void frmQuery::OnSaveHistory(wxCommandEvent& event)
844
970
{
845
 
    wxFileDialog *dlg=new wxFileDialog(this, _("Save history"), lastDir, wxEmptyString, 
 
971
    wxFileDialog *dlg=new wxFileDialog(this, _("Save history"), lastDir, wxEmptyString,
846
972
        _("Log files (*.log)|*.log|All files (*.*)|*.*"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
847
973
    if (dlg->ShowModal() == wxID_OK)
848
974
    {
855
981
 
856
982
}
857
983
 
 
984
void frmQuery::OnChangeNotebook(wxNotebookEvent& event)
 
985
{
 
986
    if(sqlNotebook && sqlNotebook->GetPageCount() >= 2)
 
987
    {
 
988
 
 
989
        if (event.GetSelection() == 0)
 
990
       {
 
991
            queryMenu->SetHelpString(MNU_EXECUTE, _("Execute query"));
 
992
            queryMenu->SetHelpString(MNU_EXECFILE, _("Execute query, write result to file"));
 
993
            toolBar->SetToolShortHelp(MNU_EXECUTE, _("Execute query"));
 
994
            toolBar->SetToolShortHelp(MNU_EXECFILE, _("Execute query, write result to file"));
 
995
 
 
996
            // Reset the panes
 
997
            if (viewMenu->IsChecked(MNU_OUTPUTPANE))
 
998
                    manager.GetPane(wxT("outputPane")).Show(true);
 
999
            if (viewMenu->IsChecked(MNU_SCRATCHPAD))
 
1000
                    manager.GetPane(wxT("scratchPad")).Show(true);
 
1001
                manager.Update();
 
1002
 
 
1003
            updateFromGqb(false);
 
1004
        }
 
1005
        else
 
1006
        {
 
1007
            queryMenu->Append(MNU_EXECUTE, _("Generate SQL from Graphical Query Builder Model"));
 
1008
            queryMenu->SetHelpString(MNU_EXECFILE, _("Generate SQL from Graphical Query Builder Model"));
 
1009
            toolBar->SetToolShortHelp(MNU_EXECUTE, _("Generate SQL from Graphical Query Builder Model"));
 
1010
            toolBar->SetToolShortHelp(MNU_EXECFILE, _("Generate SQL from Graphical Query Builder Model"));
 
1011
                manager.GetPane(wxT("outputPane")).Show(false);
 
1012
            manager.GetPane(wxT("scratchPad")).Show(false);
 
1013
                manager.Update();
 
1014
            
 
1015
            if(firstTime)        //Things that should be done on first click on GQB
 
1016
            {
 
1017
                // Size, and pause to allow the window to draw
 
1018
                adjustGQBSizes();
 
1019
                wxTheApp->Yield(true);
 
1020
 
 
1021
                // Database related Stuffs.
 
1022
                // Create a server object and connect it.
 
1023
                controller->getTablesBrowser()->refreshTables(conn);
 
1024
                firstTime=false;
 
1025
            }
 
1026
        }
 
1027
    }
 
1028
}
 
1029
 
858
1030
 
859
1031
void frmQuery::OnSetFocus(wxFocusEvent& event)
860
1032
{
926
1098
        msgHistory->Copy();
927
1099
    else if (wnd == scratchPad)
928
1100
        scratchPad->Copy();
929
 
    else 
 
1101
    else
930
1102
    {
931
1103
        wxWindow *obj = wnd;
932
1104
 
933
 
        while (obj != NULL) {
934
 
            if (obj == sqlResult) {
 
1105
        while (obj != NULL)
 
1106
        {
 
1107
            if (obj == sqlResult)
 
1108
            {
935
1109
                sqlResult->Copy();
936
1110
                break;
937
1111
            }
941
1115
    updateMenu();
942
1116
}
943
1117
 
 
1118
 
944
1119
void frmQuery::OnPaste(wxCommandEvent& ev)
945
1120
{
946
1121
    if (currentControl() == sqlQuery)
947
 
      sqlQuery->Paste();
 
1122
        sqlQuery->Paste();
948
1123
    else if (currentControl() == scratchPad)
949
 
      scratchPad->Paste();
 
1124
        scratchPad->Paste();
950
1125
}
951
1126
 
 
1127
 
952
1128
void frmQuery::OnClear(wxCommandEvent& ev)
953
1129
{
954
1130
    wxWindow *wnd=currentControl();
963
1139
        scratchPad->Clear();
964
1140
}
965
1141
 
 
1142
 
966
1143
void frmQuery::OnSelectAll(wxCommandEvent& ev)
967
1144
{
968
1145
    wxWindow *wnd=currentControl();
981
1158
        sqlResult->SelectAll();
982
1159
}
983
1160
 
 
1161
 
984
1162
void frmQuery::OnSearchReplace(wxCommandEvent& ev)
985
1163
{
986
 
      sqlQuery->OnSearchReplace(ev);
 
1164
    sqlQuery->OnSearchReplace(ev);
987
1165
}
988
1166
 
 
1167
 
989
1168
void frmQuery::OnUndo(wxCommandEvent& ev)
990
1169
{
991
1170
    sqlQuery->Undo();
992
1171
}
993
1172
 
 
1173
 
994
1174
void frmQuery::OnRedo(wxCommandEvent& ev)
995
1175
{
996
1176
    sqlQuery->Redo();
997
1177
}
998
1178
 
 
1179
 
999
1180
void frmQuery::setExtendedTitle()
1000
1181
{
1001
1182
    wxString chgStr;
1026
1207
        return;
1027
1208
 
1028
1209
    if (closing)
1029
 
                return;
 
1210
        return;
1030
1211
 
1031
 
    if (!obj || obj == sqlQuery)
 
1212
    if (obj != msgResult && obj != msgHistory)
1032
1213
    {
1033
 
        canUndo=sqlQuery->CanUndo();
1034
 
        canRedo=sqlQuery->CanRedo();
1035
 
        canPaste=sqlQuery->CanPaste();
 
1214
        if (sqlQuery)
 
1215
        {
 
1216
            canUndo=sqlQuery->CanUndo();
 
1217
            canRedo=sqlQuery->CanRedo();
 
1218
            canPaste=sqlQuery->CanPaste();
 
1219
            canAddFavourite = (sqlQuery->GetLength() > 0);
 
1220
        }
1036
1221
 
1037
1222
        canCut = true;
1038
1223
        canClear = true;
1039
1224
        canFind = true;
1040
 
 
1041
 
        canAddFavourite = (sqlQuery->GetLength() > 0);
1042
1225
    }
1043
1226
    else if (obj == msgResult || obj == msgHistory)
1044
1227
    {
1045
1228
        canClear = true;
1046
1229
    }
1047
1230
 
1048
 
 
1049
1231
    toolBar->EnableTool(MNU_UNDO, canUndo);
1050
1232
    editMenu->Enable(MNU_UNDO, canUndo);
1051
1233
 
1067
1249
    favouritesMenu->Enable(MNU_FAVOURITES_ADD, canAddFavourite);
1068
1250
}
1069
1251
 
 
1252
 
1070
1253
void frmQuery::UpdateFavouritesList()
1071
1254
{
1072
1255
    while (favouritesMenu->GetMenuItemCount() > 3)
1077
1260
    favourites->AppendAllToMenu(favouritesMenu, MNU_FAVOURITES_MANAGE+1);
1078
1261
}
1079
1262
 
 
1263
 
1080
1264
void frmQuery::UpdateMacrosList()
1081
1265
{
1082
 
        while (macrosMenu->GetMenuItemCount() > 2)
1083
 
        {
1084
 
                macrosMenu->Destroy(macrosMenu->GetMenuItems()[2]);
1085
 
        }
 
1266
    while (macrosMenu->GetMenuItemCount() > 2)
 
1267
    {
 
1268
        macrosMenu->Destroy(macrosMenu->GetMenuItems()[2]);
 
1269
    }
1086
1270
 
1087
 
        macros->AppendAllToMenu(macrosMenu, MNU_MACROS_MANAGE+1);
 
1271
    macros->AppendAllToMenu(macrosMenu, MNU_MACROS_MANAGE+1);
1088
1272
}
1089
1273
 
 
1274
 
1090
1275
void frmQuery::OnAddFavourite(wxCommandEvent &event)
1091
1276
{
1092
1277
    if (sqlQuery->GetText().Trim().IsEmpty())
1093
1278
        return;
1094
1279
    if (dlgAddFavourite(this,favourites).AddFavourite(sqlQuery->GetText()))
1095
1280
    {
1096
 
        /* Added a favourite, so save */
 
1281
        // Added a favourite, so save
1097
1282
        queryFavouriteFileProvider::SaveFavourites(favourites);
1098
1283
        UpdateFavouritesList();
1099
1284
    }
1100
1285
}
1101
1286
 
 
1287
 
1102
1288
void frmQuery::OnManageFavourites(wxCommandEvent &event)
1103
1289
{
1104
1290
    int r = dlgManageFavourites(this,favourites).ManageFavourites();
1105
1291
    if (r == 1)
1106
1292
    {
1107
 
        /* Changed something, so save */
 
1293
        // Changed something, so save
1108
1294
        queryFavouriteFileProvider::SaveFavourites(favourites);
1109
1295
        UpdateFavouritesList();
1110
1296
    }
1111
1297
    else if (r == -1)
1112
1298
    {
1113
 
        /* Changed something requiring rollback */
 
1299
        // Changed something requiring rollback
1114
1300
        delete favourites;
1115
1301
        favourites = queryFavouriteFileProvider::LoadFavourites(true);
1116
1302
        UpdateFavouritesList();
1117
1303
    }
1118
1304
}
1119
1305
 
 
1306
 
1120
1307
void frmQuery::OnSelectFavourite(wxCommandEvent &event)
1121
1308
{
1122
1309
    queryFavouriteItem *fav;
1135
1322
        else
1136
1323
        {
1137
1324
            if (sqlQuery->GetText().Last() != '\n')
1138
 
                sqlQuery->AddText(wxT("\n")); // Add a newline after the last query
 
1325
                sqlQuery->AddText(wxT("\n"));     // Add a newline after the last query
1139
1326
        }
1140
1327
    }
1141
1328
    sqlQuery->AddText(fav->GetContents());
1142
1329
}
1143
1330
 
1144
 
 
 
1331
 
1145
1332
bool frmQuery::CheckChanged(bool canVeto)
1146
1333
{
1147
1334
    if (changed && settings->GetAskSaveConfirmation())
1148
1335
    {
1149
1336
        wxString fn;
1150
1337
        if (!lastPath.IsNull())
1151
 
            fn = wxT(" in file ") + lastPath;
1152
 
        wxMessageDialog msg(this, wxString::Format(_("The text %s has changed.\nDo you want to save changes?"), fn.c_str()), _("Query"), 
1153
 
                    wxYES_NO|wxICON_EXCLAMATION|
1154
 
                    (canVeto ? wxCANCEL : 0));
 
1338
            fn = wxString::Format(_("The text in file %s has changed.\nDo you want to save changes?"), lastPath.c_str());
 
1339
        else
 
1340
            fn = _("The text has changed.\nDo you want to save changes?");
 
1341
        wxMessageDialog msg(this, fn, _("Query"),
 
1342
            wxYES_NO|wxICON_EXCLAMATION|
 
1343
            (canVeto ? wxCANCEL : 0));
1155
1344
 
1156
1345
        wxCommandEvent noEvent;
1157
1346
        switch (msg.ShowModal())
1178
1367
    {
1179
1368
        if (event.CanVeto())
1180
1369
        {
1181
 
            wxMessageDialog msg(this, _("A query is running. Do you wish to cancel it?"), _("Query"), 
1182
 
                        wxYES_NO|wxNO_DEFAULT|wxICON_EXCLAMATION);
 
1370
            wxMessageDialog msg(this, _("A query is running. Do you wish to cancel it?"), _("Query"),
 
1371
                wxYES_NO|wxNO_DEFAULT|wxICON_EXCLAMATION);
1183
1372
 
1184
1373
            if (msg.ShowModal() == wxID_NO)
1185
1374
            {
1204
1393
        return;
1205
1394
    }
1206
1395
 
 
1396
    closing = true;
 
1397
 
 
1398
    // Reset the panes
 
1399
    if (viewMenu->IsChecked(MNU_OUTPUTPANE))
 
1400
        manager.GetPane(wxT("outputPane")).Show(true);
 
1401
    if (viewMenu->IsChecked(MNU_SCRATCHPAD))
 
1402
        manager.GetPane(wxT("scratchPad")).Show(true);
 
1403
    manager.Update();
 
1404
 
1207
1405
    Hide();
1208
1406
 
 
1407
    sqlQuery->Disconnect(wxID_ANY, wxEVT_SET_FOCUS,wxFocusEventHandler(frmQuery::OnFocus));
 
1408
    sqlResult->Disconnect(wxID_ANY, wxEVT_SET_FOCUS, wxFocusEventHandler(frmQuery::OnFocus));
 
1409
    msgResult->Disconnect(wxID_ANY, wxEVT_SET_FOCUS, wxFocusEventHandler(frmQuery::OnFocus));
 
1410
    msgHistory->Disconnect(wxID_ANY, wxEVT_SET_FOCUS, wxFocusEventHandler(frmQuery::OnFocus));
 
1411
    
 
1412
    controller->nullView();                   //to avoid bug on *nix when deleting controller
 
1413
 
 
1414
    settings->SetExplainAnalyze(queryMenu->IsChecked(MNU_ANALYZE));
 
1415
    settings->SetExplainVerbose(queryMenu->IsChecked(MNU_VERBOSE));
 
1416
 
 
1417
    sqlResult->Abort();                           // to make sure conn is unused
 
1418
 
1209
1419
    Destroy();
 
1420
 
1210
1421
}
1211
1422
 
1212
1423
 
1213
1424
void frmQuery::OnChangeStc(wxStyledTextEvent& event)
1214
1425
{
1215
 
        // The STC seems to fire this event even if it loses focus. Fortunately,
1216
 
        // that seems to be m_modificationType == 512.
 
1426
    // The STC seems to fire this event even if it loses focus. Fortunately,
 
1427
    // that seems to be m_modificationType == 512.
1217
1428
    if (!changed && event.m_modificationType != 512)
1218
1429
    {
1219
1430
        changed=true;
1222
1433
    updateMenu();
1223
1434
}
1224
1435
 
 
1436
 
1225
1437
void frmQuery::OnPositionStc(wxStyledTextEvent& event)
1226
1438
{
1227
1439
    wxString pos;
1243
1455
    {
1244
1456
        sqlQuery->SetText(str);
1245
1457
        sqlQuery->Colourise(0, str.Length());
1246
 
        wxSafeYield();  // needed to process sqlQuery modify event
 
1458
        wxSafeYield();                            // needed to process sqlQuery modify event
1247
1459
        changed = false;
1248
1460
        setExtendedTitle();
1249
1461
        SetLineEndingStyle();
1250
1462
        UpdateRecentFiles();
1251
1463
    }
1252
1464
}
1253
 
        
 
1465
 
 
1466
 
1254
1467
void frmQuery::OnNew(wxCommandEvent& event)
1255
1468
{
1256
1469
    frmQuery *fq = new frmQuery(mainForm, wxEmptyString, conn->Duplicate(), wxEmptyString);
1259
1472
    fq->Go();
1260
1473
}
1261
1474
 
 
1475
 
1262
1476
void frmQuery::OnOpen(wxCommandEvent& event)
1263
1477
{
1264
1478
    if (CheckChanged(true))
1265
1479
        return;
1266
1480
 
1267
 
    wxFileDialog dlg(this, _("Open query file"), lastDir, wxT(""), 
1268
 
        _("Query files (*.sql)|*.sql|All files (*.*)|*.*"), wxFD_OPEN);
 
1481
    wxFileDialog dlg(this, _("Open query file"), lastDir, wxT(""),
 
1482
        _("Query files (*.sql)|*.sql|pgScript files (*.pgs)|*.pgs|All files (*.*)|*.*"), wxFD_OPEN);
1269
1483
    if (dlg.ShowModal() == wxID_OK)
1270
1484
    {
1271
1485
        lastFilename=dlg.GetFilename();
1275
1489
    }
1276
1490
}
1277
1491
 
 
1492
 
1278
1493
void frmQuery::OnSave(wxCommandEvent& event)
1279
1494
{
1280
1495
    bool modeUnicode = settings->GetUnicodeFile();
1287
1502
 
1288
1503
    wxUtfFile file(lastPath, wxFile::write, modeUnicode ? wxFONTENCODING_UTF8:wxFONTENCODING_DEFAULT);
1289
1504
    if (file.IsOpened())
1290
 
     {
 
1505
    {
1291
1506
        if ((file.Write(sqlQuery->GetText()) == 0) && (!modeUnicode))
1292
1507
            wxMessageBox(_("Query text incomplete.\nQuery contained characters that could not be converted to the local charset.\nPlease correct the data or try using UTF8 instead."));
1293
1508
        file.Close();
1301
1516
    }
1302
1517
}
1303
1518
 
 
1519
 
 
1520
// Set the line ending style based on the current document.
1304
1521
void frmQuery::SetLineEndingStyle()
1305
1522
{
1306
1523
    // Detect the file mode
1313
1530
    bool haveCR = reCR->Matches(sqlQuery->GetText());
1314
1531
    int mode = GetLineEndingStyle();
1315
1532
 
1316
 
    if (haveLF && haveCR ||
1317
 
        haveLF && haveCRLF ||
1318
 
        haveCR && haveCRLF)
 
1533
    if ((haveLF && haveCR) ||
 
1534
        (haveLF && haveCRLF) ||
 
1535
        (haveCR && haveCRLF))
1319
1536
    {
1320
 
        wxMessageBox(_("This file contain mixed line endings. They will be converted to the current setting."), _("Warning"), wxICON_INFORMATION);
 
1537
        wxMessageBox(_("This file contains mixed line endings. They will be converted to the current setting."), _("Warning"), wxICON_INFORMATION);
1321
1538
        sqlQuery->ConvertEOLs(mode);
1322
1539
        changed=true;
1323
1540
        setExtendedTitle();
1362
1579
    delete reLF;
1363
1580
}
1364
1581
 
 
1582
 
 
1583
// Get the line ending style
1365
1584
int frmQuery::GetLineEndingStyle()
1366
1585
{
1367
1586
    if (lineEndMenu->IsChecked(MNU_LF))
1370
1589
        return wxSTC_EOL_CRLF;
1371
1590
    else if (lineEndMenu->IsChecked(MNU_CR))
1372
1591
        return wxSTC_EOL_CR;
1373
 
    else 
 
1592
    else
1374
1593
        return sqlQuery->GetEOLMode();
1375
1594
}
1376
1595
 
 
1596
 
 
1597
// User-set the current EOL mode for the form
1377
1598
void frmQuery::OnSetEOLMode(wxCommandEvent& event)
1378
1599
{
1379
1600
    int mode = GetLineEndingStyle();
1380
1601
    sqlQuery->ConvertEOLs(mode);
1381
 
 
 
1602
    sqlQuery->SetEOLMode(mode);
 
1603
    settings->SetLineEndingType(mode);
 
1604
 
 
1605
    SetEOLModeDisplay(mode);
 
1606
 
 
1607
    if (!changed)
 
1608
    {
 
1609
        changed=true;
 
1610
        setExtendedTitle();
 
1611
    }
 
1612
    
 
1613
    pgScript->SetConnection(conn);
 
1614
}
 
1615
 
 
1616
 
 
1617
// Display the EOL mode settings on the form
 
1618
void frmQuery::SetEOLModeDisplay(int mode)
 
1619
{
1382
1620
    switch(mode)
1383
1621
    {
1384
1622
 
1400
1638
        default:
1401
1639
            wxLogError(wxT("Someone created a new line ending style! Run, run for your lives!!"));
1402
1640
    }
1403
 
 
1404
 
    if (!changed)
1405
 
    {
1406
 
        changed=true;
1407
 
        setExtendedTitle();  
1408
 
    }
1409
1641
}
1410
1642
 
 
1643
 
1411
1644
void frmQuery::OnSaveAs(wxCommandEvent& event)
1412
1645
{
1413
 
    wxFileDialog *dlg=new wxFileDialog(this, _("Save query file as"), lastDir, lastFilename, 
 
1646
    wxFileDialog *dlg=new wxFileDialog(this, _("Save query file as"), lastDir, lastFilename,
1414
1647
        _("Query files (*.sql)|*.sql|All files (*.*)|*.*"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
1415
1648
    if (dlg->ShowModal() == wxID_OK)
1416
1649
    {
1419
1652
        lastPath = dlg->GetPath();
1420
1653
        switch (dlg->GetFilterIndex())
1421
1654
        {
1422
 
            case 0: 
 
1655
            case 0:
1423
1656
#ifdef __WXMAC__
1424
 
        if (!lastPath.Contains(wxT(".")))
1425
 
            lastPath += wxT(".sql");
 
1657
                if (!lastPath.Contains(wxT(".")))
 
1658
                    lastPath += wxT(".sql");
1426
1659
#endif
1427
1660
                break;
1428
1661
            case 1:
1429
1662
#ifdef __WXMAC__
1430
1663
                if (!lastPath.Contains(wxT(".")))
1431
 
                        lastPath += wxT(".sql");
 
1664
                    lastPath += wxT(".sql");
1432
1665
#endif
1433
1666
                break;
1434
1667
            default:
1456
1689
    delete dlg;
1457
1690
}
1458
1691
 
 
1692
 
1459
1693
void frmQuery::OnQuickReport(wxCommandEvent& event)
1460
1694
{
1461
1695
    wxDateTime now = wxDateTime::Now();
1492
1726
    queryMenu->Enable(MNU_CANCEL, false);
1493
1727
    SetStatusText(_("Cancelling."), STATUSPOS_MSGS);
1494
1728
 
1495
 
    sqlResult->Abort();
 
1729
    if (sqlResult->RunStatus() == CTLSQL_RUNNING)
 
1730
        sqlResult->Abort();
 
1731
    else if (pgScript->IsRunning())
 
1732
        pgScript->Terminate();
1496
1733
    aborted=true;
1497
1734
}
1498
1735
 
1499
1736
 
1500
1737
void frmQuery::OnExplain(wxCommandEvent& event)
1501
1738
{
 
1739
    if(sqlNotebook->GetSelection()==1)
 
1740
    {
 
1741
        if (!updateFromGqb(true))
 
1742
            return;
 
1743
    }
 
1744
 
1502
1745
    wxString query=sqlQuery->GetSelectedText();
1503
1746
    if (query.IsNull())
1504
1747
        query = sqlQuery->GetText();
1519
1762
        sql += wxT("ANALYZE ");
1520
1763
    if (verbose)
1521
1764
        sql += wxT("VERBOSE ");
1522
 
    
 
1765
 
1523
1766
    int offset=sql.Length();
1524
1767
 
1525
1768
    sql += query;
1534
1777
    execQuery(sql, resultToRetrieve, true, offset, false, true, verbose);
1535
1778
}
1536
1779
 
 
1780
// Update the main SQL query from the GQB if desired
 
1781
bool frmQuery::updateFromGqb(bool executing)
 
1782
{
 
1783
    if (closing)
 
1784
        return false;
 
1785
 
 
1786
    // Make sure this doesn't get call recursively through an event
 
1787
    if (gqbUpdateRunning)
 
1788
        return false;
 
1789
 
 
1790
    gqbUpdateRunning = true;
 
1791
 
 
1792
    // Execute Generation of SQL sentence from GQB
 
1793
    bool canGenerate=false;
 
1794
    wxString newQuery = controller->generateSQL();
 
1795
 
 
1796
    // If the new query is empty, don't do anything
 
1797
    if (newQuery.IsEmpty())
 
1798
    {
 
1799
        wxMessageBox(_("No SQL query was generated."), wxT("Graphical Query Builder"), wxICON_INFORMATION);
 
1800
        gqbUpdateRunning = false;
 
1801
        return false;
 
1802
    }
 
1803
 
 
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")) 
 
1806
    {
 
1807
        wxString fn;
 
1808
        if (executing)
 
1809
            fn = _("The generated SQL query has changed.\nDo you want to update it and execute the query?");
 
1810
        else
 
1811
            fn = _("The generated SQL query has changed.\nDo you want to update it?");
 
1812
 
 
1813
        wxMessageDialog msg(this, fn, _("Query"), wxYES_NO|wxICON_EXCLAMATION);
 
1814
        if(msg.ShowModal() == wxID_YES && changed)
 
1815
        {
 
1816
            canGenerate=true;
 
1817
        }
 
1818
                else
 
1819
                {
 
1820
                        gqbUpdateRunning = false;
 
1821
                }
 
1822
    }
 
1823
    else
 
1824
    {
 
1825
        canGenerate=true;
 
1826
    }
 
1827
 
 
1828
    if(canGenerate)
 
1829
    {
 
1830
        sqlQuery->ClearAll();
 
1831
        sqlQuery->AddText(newQuery + wxT("\n"));
 
1832
            sqlQuery->Colourise(0, sqlQuery->GetText().Length());
 
1833
            sqlNotebook->SetSelection(0);
 
1834
        changed=true;
 
1835
        
 
1836
        gqbUpdateRunning = false;
 
1837
        return true;
 
1838
    }
 
1839
 
 
1840
    return false;
 
1841
}
 
1842
 
1537
1843
void frmQuery::OnExecute(wxCommandEvent& event)
1538
1844
{
 
1845
    if(sqlNotebook->GetSelection()==1)
 
1846
    {
 
1847
        if (!updateFromGqb(true))
 
1848
            return;
 
1849
    }
 
1850
 
1539
1851
    wxString query=sqlQuery->GetSelectedText();
1540
1852
    if (query.IsNull())
1541
1853
        query = sqlQuery->GetText();
1542
1854
 
1543
1855
    if (query.IsNull())
1544
1856
        return;
 
1857
 
1545
1858
    execQuery(query);
1546
1859
    sqlQuery->SetFocus();
1547
1860
}
1548
1861
 
1549
1862
 
 
1863
void frmQuery::OnExecScript(wxCommandEvent& event)
 
1864
{
 
1865
    // Get the script
 
1866
    wxString query = sqlQuery->GetSelectedText();
 
1867
    if (query.IsNull())
 
1868
        query = sqlQuery->GetText();
 
1869
    if (query.IsNull())
 
1870
        return;
 
1871
 
 
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)
 
1875
    {
 
1876
        wxMessageBox(_("pgScript already running."), _("Concurrent execution of pgScripts is not supported at this time."), wxICON_WARNING);
 
1877
        return;
 
1878
    }
 
1879
    frmQuery::ms_pgScriptRunning = true;
 
1880
 
 
1881
    // Clear markers and indicators
 
1882
    sqlQuery->MarkerDeleteAll(0);
 
1883
    sqlQuery->StartStyling(0, wxSTC_INDICS_MASK);
 
1884
    sqlQuery->SetStyling(sqlQuery->GetText().Length(), 0);
 
1885
 
 
1886
    // Menu stuff to initialize
 
1887
    setTools(true);
 
1888
    queryMenu->Enable(MNU_SAVEHISTORY, true);
 
1889
    queryMenu->Enable(MNU_CLEARHISTORY, true);
 
1890
 
 
1891
    // Window stuff
 
1892
    explainCanvas->Clear();
 
1893
    msgResult->Clear();
 
1894
    outputPane->SetSelection(2);
 
1895
 
 
1896
    // Status text
 
1897
    SetStatusText(wxT(""), STATUSPOS_SECS);
 
1898
    SetStatusText(_("pgScript is running."), STATUSPOS_MSGS);
 
1899
    SetStatusText(wxT(""), STATUSPOS_ROWS);
 
1900
 
 
1901
    // History
 
1902
    msgHistory->AppendText(_("-- Executing pgScript\n"));
 
1903
    Update();
 
1904
    wxTheApp->Yield(true);
 
1905
 
 
1906
    // Timer
 
1907
    startTimeQuery = wxGetLocalTimeMillis();
 
1908
    timer.Start(10);
 
1909
    
 
1910
    // Delete previous variables
 
1911
    pgScript->ClearSymbols();
 
1912
 
 
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);
 
1917
    aborted = false;
 
1918
}
 
1919
 
 
1920
 
 
1921
 
1550
1922
void frmQuery::OnExecFile(wxCommandEvent &event)
1551
1923
{
 
1924
    if(sqlNotebook->GetSelection()==1)
 
1925
    {
 
1926
        if (!updateFromGqb(true))
 
1927
            return;
 
1928
    }
 
1929
 
1552
1930
    wxString query=sqlQuery->GetSelectedText();
1553
1931
    if (query.IsNull())
1554
1932
        query = sqlQuery->GetText();
1555
1933
 
1556
1934
    if (query.IsNull())
1557
1935
        return;
 
1936
 
1558
1937
    execQuery(query, 0, false, 0, true);
1559
1938
    sqlQuery->SetFocus();
1560
1939
}
1561
1940
 
 
1941
 
1562
1942
void frmQuery::OnMacroManage(wxCommandEvent &event)
1563
1943
{
1564
 
        int r = dlgManageMacros(this,mainForm,macros).ManageMacros();
 
1944
    int r = dlgManageMacros(this,mainForm,macros).ManageMacros();
1565
1945
    if (r == 1)
1566
1946
    {
1567
 
        /* Changed something, so save */
 
1947
        // Changed something, so save
1568
1948
        queryMacroFileProvider::SaveMacros(macros);
1569
1949
        UpdateMacrosList();
1570
1950
    }
1571
1951
    else if (r == -1)
1572
1952
    {
1573
 
        /* Changed something requiring rollback */
 
1953
        // Changed something requiring rollback
1574
1954
        delete macros;
1575
1955
        macros = queryMacroFileProvider::LoadMacros(true);
1576
1956
        UpdateMacrosList();
1578
1958
 
1579
1959
}
1580
1960
 
 
1961
 
1581
1962
void frmQuery::OnMacroInvoke(wxCommandEvent &event)
1582
1963
{
1583
1964
    queryMacroItem *mac;
1586
1967
    if (!mac)
1587
1968
        return;
1588
1969
 
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
1592
1973
 
1593
 
        if (query.Find(wxT("$SELECTION$")) != wxNOT_FOUND)
1594
 
        {
1595
 
                wxString selection = sqlQuery->GetSelectedText();
1596
 
                if (selection.IsEmpty())
1597
 
                {
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);
1599
 
                        return;
1600
 
                }
1601
 
                query.Replace(wxT("$SELECTION$"), selection);
1602
 
        }
 
1974
    if (query.Find(wxT("$SELECTION$")) != wxNOT_FOUND)
 
1975
    {
 
1976
        wxString selection = sqlQuery->GetSelectedText();
 
1977
        if (selection.IsEmpty())
 
1978
        {
 
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);
 
1980
            return;
 
1981
        }
 
1982
        query.Replace(wxT("$SELECTION$"), selection);
 
1983
    }
1603
1984
    execQuery(query);
1604
1985
    sqlQuery->SetFocus();
1605
1986
}
1606
1987
 
 
1988
 
1607
1989
void frmQuery::setTools(const bool running)
1608
1990
{
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);
1620
2005
}
1621
2006
 
1622
2007
 
1633
2018
    SetStatusText(str, STATUSPOS_MSGS);
1634
2019
}
1635
2020
 
 
2021
 
1636
2022
void frmQuery::execQuery(const wxString &query, int resultToRetrieve, bool singleResult, const int queryOffset, bool toFile, bool explain, bool verbose)
1637
2023
{
1638
2024
    setTools(true);
1684
2070
    completeQuery(false, false, false);
1685
2071
}
1686
2072
 
 
2073
 
1687
2074
// When the query completes, it raises an event which we process here.
1688
2075
void frmQuery::OnQueryComplete(wxCommandEvent &ev)
1689
2076
{
1695
2082
    {
1696
2083
        wxTheApp->Yield(true);
1697
2084
    }
 
2085
    
 
2086
    while (pgScript->IsRunning())
 
2087
    {
 
2088
        wxLogInfo(wxT("SQL Query box: Waiting for script to abort"));
 
2089
        wxSleep(1);
 
2090
    }
1698
2091
 
1699
2092
    timer.Stop();
1700
2093
 
1723
2116
            else if (insertedCount == 1 && insertedOid)
1724
2117
            {
1725
2118
                showMessage(wxString::Format(_("Query returned successfully: one row with OID %d inserted, %s ms execution time."),
1726
 
                    insertedOid, elapsedQuery.ToString().c_str()), 
 
2119
                    insertedOid, elapsedQuery.ToString().c_str()),
1727
2120
                    wxString::Format(_("One Row with OID %d inserted."), insertedOid));
1728
2121
            }
1729
2122
            else
1730
2123
            {
1731
 
                showMessage(wxString::Format(_("Query returned successfully: %d rows affected, %s ms execution time."),
1732
 
                    insertedCount, elapsedQuery.ToString().c_str()), 
1733
 
                    wxString::Format(_("%d rows affected."), insertedCount));
 
2124
                showMessage(wxString::Format(
 
2125
                    wxPLURAL(
 
2126
                        "Query returned successfully: %d row affected, %s ms execution time.", 
 
2127
                        "Query returned successfully: %d rows affected, %s ms execution time.", 
 
2128
                        insertedCount),
 
2129
                    insertedCount, elapsedQuery.ToString().c_str()),
 
2130
                    wxString::Format(wxPLURAL("%d row affected.", "%d rows affected.", insertedCount), insertedCount));
1734
2131
            }
1735
2132
        }
1736
2133
        else
1741
2138
 
1742
2139
            long errPos;
1743
2140
            err.statement_pos.ToLong(&errPos);
1744
 
            
 
2141
 
1745
2142
            showMessage(wxString::Format(wxT("********** %s **********\n"), _("Error")));
1746
2143
            showMessage(errMsg);
1747
2144
 
1751
2148
                if (selStart == selEnd)
1752
2149
                    selStart=0;
1753
2150
 
1754
 
                errPos -= qi->queryOffset;  // do not count EXPLAIN or similar
 
2151
                errPos -= qi->queryOffset;        // do not count EXPLAIN or similar
1755
2152
 
1756
2153
                // Set an indicator on the error word (break on any kind of bracket, a space or full stop)
1757
2154
                int sPos = errPos + selStart - 1, wEnd = 1;
1758
2155
                sqlQuery->StartStyling(sPos, wxSTC_INDICS_MASK);
1759
 
                while(sqlQuery->GetCharAt(sPos + wEnd) != ' ' && 
1760
 
                      sqlQuery->GetCharAt(sPos + wEnd) != '(' && 
1761
 
                      sqlQuery->GetCharAt(sPos + wEnd) != '{' && 
1762
 
                      sqlQuery->GetCharAt(sPos + wEnd) != '[' && 
1763
 
                      sqlQuery->GetCharAt(sPos + wEnd) != '.' &&
1764
 
                      (unsigned int)(sPos + wEnd) < sqlQuery->GetText().Length())
 
2156
                while(sqlQuery->GetCharAt(sPos + wEnd) != ' ' &&
 
2157
                    sqlQuery->GetCharAt(sPos + wEnd) != '(' &&
 
2158
                    sqlQuery->GetCharAt(sPos + wEnd) != '{' &&
 
2159
                    sqlQuery->GetCharAt(sPos + wEnd) != '[' &&
 
2160
                    sqlQuery->GetCharAt(sPos + wEnd) != '.' &&
 
2161
                    (unsigned int)(sPos + wEnd) < sqlQuery->GetText().Length())
1765
2162
                    wEnd++;
1766
2163
                sqlQuery->SetStyling(wEnd, wxSTC_INDIC0_MASK);
1767
2164
 
1789
2186
 
1790
2187
        if (qi->toFile)
1791
2188
        {
1792
 
            SetStatusText(wxString::Format(_("%d rows."), rowsTotal), STATUSPOS_ROWS);
 
2189
            SetStatusText(wxString::Format(wxPLURAL("%d row.", "%d rows.", rowsTotal), rowsTotal), STATUSPOS_ROWS);
1793
2190
 
1794
2191
            if (rowsTotal)
1795
2192
            {
1814
2211
            {
1815
2212
                sqlResult->DisplayData(true);
1816
2213
 
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."));
1818
2217
            }
1819
2218
            else
1820
2219
            {
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);
1823
2222
 
1824
2223
                sqlResult->DisplayData();
1825
2224
 
1826
 
 
1827
 
 
1828
2225
                SetStatusText(elapsedQuery.ToString() + wxT(" ms"), STATUSPOS_SECS);
1829
2226
 
1830
2227
                str= _("Total query runtime: ") + elapsedQuery.ToString() + wxT(" ms.\n") ;
1831
2228
                msgResult->AppendText(str);
1832
2229
                msgHistory->AppendText(str);
1833
2230
 
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."));
1835
2232
            }
1836
 
            SetStatusText(wxString::Format(_("%d rows."), rowsTotal), STATUSPOS_ROWS);
 
2233
            SetStatusText(wxString::Format(wxPLURAL("%d row.", "%d rows.", rowsTotal), rowsTotal), STATUSPOS_ROWS);
1837
2234
        }
1838
2235
    }
1839
2236
 
1840
2237
    completeQuery(done, qi->explain, qi->verbose);
1841
2238
}
1842
2239
 
 
2240
 
 
2241
void frmQuery::OnScriptComplete(wxCommandEvent &ev)
 
2242
{
 
2243
    // Stop timers
 
2244
    timer.Stop();
 
2245
    pgsTimer->Stop();
 
2246
    
 
2247
    // Write output
 
2248
    writeScriptOutput();
 
2249
 
 
2250
    // Reset tools
 
2251
    setTools(false);
 
2252
 
 
2253
    // Unlock our pseudo-mutex thingy
 
2254
    frmQuery::ms_pgScriptRunning = false;
 
2255
 
 
2256
    // Manage timer
 
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);
 
2262
    
 
2263
    // Check whether there was an error/exception
 
2264
    if (pgScript->errorOccurred() && pgScript->errorLine() >= 1)
 
2265
    {
 
2266
        // Find out what the line number is
 
2267
        int selStart = sqlQuery->GetSelectionStart(), selEnd = sqlQuery->GetSelectionEnd();
 
2268
        if (selStart == selEnd)
 
2269
            selStart = 0;
 
2270
        int line = 0, maxLine = sqlQuery->GetLineCount();
 
2271
        while (line < maxLine && sqlQuery->GetLineEndPosition(line) < selStart)
 
2272
            line++;
 
2273
        line += pgScript->errorLine() - 1;
 
2274
        
 
2275
        // Mark the line where the error occurred
 
2276
        sqlQuery->MarkerAdd(line, 0);
 
2277
        
 
2278
        // Go to that line
 
2279
        sqlQuery->GotoPos(sqlQuery->GetLineEndPosition(line));
 
2280
    }
 
2281
}
 
2282
 
 
2283
void frmQuery::writeScriptOutput()
 
2284
{
 
2285
    pgScript->LockOutput();
 
2286
    
 
2287
    wxString output(pgsOutputString);
 
2288
    pgsOutputString.Clear();
 
2289
    msgResult->AppendText(output);
 
2290
    
 
2291
    pgScript->UnlockOutput();
 
2292
}
 
2293
 
1843
2294
// Complete the processing of a query
1844
2295
void frmQuery::completeQuery(bool done, bool explain, bool verbose)
1845
2296
{
1869
2320
        if (statusMsg.Last() == '.')
1870
2321
            statusMsg = statusMsg.Left(statusMsg.Length() - 1);
1871
2322
 
1872
 
        SetStatusText(wxString::Format(_("%s (%d asynchronous notifications received)."), statusMsg.c_str(), notifies), STATUSPOS_MSGS);
 
2323
        SetStatusText(wxString::Format(
 
2324
            wxPLURAL("%s (%d asynchronous notification received).", "%s (%d asynchronous notifications received).", notifies),
 
2325
            statusMsg.c_str(), notifies), STATUSPOS_MSGS);
1873
2326
    }
1874
2327
 
1875
2328
    msgResult->AppendText(wxT("\n"));
1923
2376
    sqlQuery->SetFocus();
1924
2377
}
1925
2378
 
 
2379
 
1926
2380
void frmQuery::OnTimer(wxTimerEvent & event)
1927
2381
{
1928
2382
    elapsedQuery=wxGetLocalTimeMillis() - startTimeQuery;
1932
2386
    if (!str.IsEmpty())
1933
2387
    {
1934
2388
        msgResult->AppendText(str + wxT("\n"));
1935
 
        msgHistory->AppendText(str + wxT("\n")); 
 
2389
        msgHistory->AppendText(str + wxT("\n"));
1936
2390
    }
1937
2391
 
1938
2392
    // Increase the granularity for longer running queries
1943
2397
    }
1944
2398
}
1945
2399
 
 
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()
 
2403
{
 
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]
 
2406
    manager.Update();
 
2407
    sqlNotebook->Refresh();
 
2408
    wxSize s = sqlNotebook->GetSize();
 
2409
    s.SetWidth(200);
 
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());
 
2413
 
 
2414
    // Now Adjust Sash Horizontal
 
2415
    s = sqlNotebook->GetSize();
 
2416
    controller->setSashHorizPosition(s.GetHeight()-150);
 
2417
 
 
2418
    // Adjust GQB grids internal columns sizes
 
2419
    controller->calcGridColsSizes();
 
2420
}
 
2421
 
 
2422
 
 
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)
 
2427
{
 
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);
 
2432
}
 
2433
 
 
2434
 
 
2435
 
 
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)
 
2439
{
 
2440
    adjustGQBSizes();
 
2441
    adjustSizesTimer->Stop();
 
2442
}
 
2443
 
 
2444
void frmQuery::OnBlockIndent(wxCommandEvent& event) 
 
2445
 
2446
    sqlQuery->CmdKeyExecute(wxSTC_CMD_TAB);
 
2447
}
 
2448
 
 
2449
void frmQuery::OnBlockOutDent(wxCommandEvent& event) 
 
2450
 
2451
    sqlQuery->CmdKeyExecute(wxSTC_CMD_BACKTAB); 
 
2452
}
 
2453
 
 
2454
void frmQuery::OnChangeToUpperCase(wxCommandEvent& event)
 
2455
{
 
2456
    sqlQuery->UpperCase();
 
2457
}
 
2458
 
 
2459
void frmQuery::OnChangeToLowerCase(wxCommandEvent& event)
 
2460
{
 
2461
    sqlQuery->LowerCase();
 
2462
}
 
2463
 
 
2464
void frmQuery::OnCommentText(wxCommandEvent& event)
 
2465
{
 
2466
    sqlQuery->BlockComment(false);
 
2467
}
 
2468
 
 
2469
void frmQuery::OnUncommentText(wxCommandEvent& event)
 
2470
{
 
2471
    sqlQuery->BlockComment(true);
 
2472
}
 
2473
 
1946
2474
///////////////////////////////////////////////////////
1947
2475
 
1948
 
 
1949
2476
wxWindow *queryToolBaseFactory::StartDialogSql(frmMain *form, pgObject *obj, const wxString &sql)
1950
2477
{
1951
2478
    pgDatabase *db=obj->GetDatabase();
1965
2492
    return obj && obj->GetDatabase() && obj->GetDatabase()->GetConnected();
1966
2493
}
1967
2494
 
 
2495
 
1968
2496
bool queryToolDataFactory::CheckEnable(pgObject *obj)
1969
2497
{
1970
2498
    return queryToolBaseFactory::CheckEnable(obj) && !obj->IsCollection() &&
1972
2500
}
1973
2501
 
1974
2502
 
1975
 
 
1976
 
queryToolFactory::queryToolFactory(menuFactoryList *list, wxMenu *mnu, wxToolBar *toolbar) : queryToolBaseFactory(list)
 
2503
queryToolFactory::queryToolFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar) : queryToolBaseFactory(list)
1977
2504
{
1978
 
    mnu->Append(id, _("&Query tool"), _("Execute arbitrary SQL queries."));
1979
 
    toolbar->AddTool(id, _("Query tool"), wxBitmap(sql_xpm), _("Execute arbitrary SQL queries."), wxITEM_NORMAL);
 
2505
    mnu->Append(id, _("&Query tool\tCtrl-E"), _("Execute arbitrary SQL queries."));
 
2506
    toolbar->AddTool(id, _("Query tool\tCtrl-E"), wxBitmap(sql_xpm), _("Execute arbitrary SQL queries."), wxITEM_NORMAL);
1980
2507
}
1981
2508
 
1982
2509
 
1983
2510
wxWindow *queryToolFactory::StartDialog(frmMain *form, pgObject *obj)
1984
2511
{
1985
2512
    wxString qry;
1986
 
    if (settings->GetStickySql()) 
 
2513
    if (settings->GetStickySql())
1987
2514
        qry = obj->GetSql(form->GetBrowser());
1988
2515
    return StartDialogSql(form, obj, qry);
1989
2516
}
1990
2517
 
1991
2518
 
1992
 
queryToolSqlFactory::queryToolSqlFactory(menuFactoryList *list, wxMenu *mnu, wxToolBar *toolbar) : queryToolBaseFactory(list)
 
2519
queryToolSqlFactory::queryToolSqlFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar) : queryToolBaseFactory(list)
1993
2520
{
1994
2521
    mnu->Append(id, _("CREATE script"), _("Start Query tool with CREATE script."));
1995
2522
    if (toolbar)
2002
2529
    return StartDialogSql(form, obj, obj->GetSql(form->GetBrowser()));
2003
2530
}
2004
2531
 
 
2532
 
2005
2533
bool queryToolSqlFactory::CheckEnable(pgObject *obj)
2006
2534
{
2007
2535
    return queryToolBaseFactory::CheckEnable(obj) && obj->CanCreate() && !obj->IsCollection();
2008
2536
}
2009
2537
 
2010
2538
 
2011
 
queryToolSelectFactory::queryToolSelectFactory(menuFactoryList *list, wxMenu *mnu, wxToolBar *toolbar) : queryToolDataFactory(list)
 
2539
queryToolSelectFactory::queryToolSelectFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar) : queryToolDataFactory(list)
2012
2540
{
2013
2541
    mnu->Append(id, _("SELECT script"), _("Start query tool with SELECT script."));
2014
2542
}
2026
2554
        pgView *view = (pgView*)obj;
2027
2555
        return StartDialogSql(form, obj, view->GetSelectSql(form->GetBrowser()));
2028
2556
    }
2029
 
    return 0;
2030
 
}
2031
 
 
2032
 
 
2033
 
queryToolUpdateFactory::queryToolUpdateFactory(menuFactoryList *list, wxMenu *mnu, wxToolBar *toolbar) : queryToolDataFactory(list)
 
2557
    else if (obj->IsCreatedBy(extTableFactory))
 
2558
    {
 
2559
        gpExtTable *exttable = (gpExtTable*)obj;
 
2560
        return StartDialogSql(form, obj, exttable->GetSelectSql(form->GetBrowser()));
 
2561
    }
 
2562
    return 0;
 
2563
}
 
2564
 
 
2565
 
 
2566
queryToolDeleteFactory::queryToolDeleteFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar) : queryToolDataFactory(list)
 
2567
{
 
2568
    mnu->Append(id, _("DELETE script"), _("Start query tool with DELETE script."));
 
2569
}
 
2570
 
 
2571
 
 
2572
bool queryToolDeleteFactory::CheckEnable(pgObject *obj)
 
2573
{
 
2574
    if (!queryToolDataFactory::CheckEnable(obj))
 
2575
        return false;
 
2576
    if (obj->IsCreatedBy(tableFactory))
 
2577
        return true;
 
2578
    return false;
 
2579
}
 
2580
 
 
2581
 
 
2582
wxWindow *queryToolDeleteFactory::StartDialog(frmMain *form, pgObject *obj)
 
2583
{
 
2584
    if (obj->IsCreatedBy(tableFactory))
 
2585
    {
 
2586
        pgTable *table = (pgTable*)obj;
 
2587
        return StartDialogSql(form, obj, table->GetDeleteSql(form->GetBrowser()));
 
2588
    }
 
2589
    return 0;
 
2590
}
 
2591
 
 
2592
 
 
2593
queryToolUpdateFactory::queryToolUpdateFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar) : queryToolDataFactory(list)
2034
2594
{
2035
2595
    mnu->Append(id, _("UPDATE script"), _("Start query tool with UPDATE script."));
2036
2596
}
2048
2608
        pgView *view = (pgView*)obj;
2049
2609
        return StartDialogSql(form, obj, view->GetUpdateSql(form->GetBrowser()));
2050
2610
    }
 
2611
 
2051
2612
    return 0;
2052
2613
}
2053
2614
 
 
2615
 
2054
2616
bool queryToolUpdateFactory::CheckEnable(pgObject *obj)
2055
2617
{
2056
2618
    if (!queryToolDataFactory::CheckEnable(obj))
2063
2625
}
2064
2626
 
2065
2627
 
2066
 
 
2067
 
queryToolInsertFactory::queryToolInsertFactory(menuFactoryList *list, wxMenu *mnu, wxToolBar *toolbar) : queryToolDataFactory(list)
 
2628
queryToolInsertFactory::queryToolInsertFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar) : queryToolDataFactory(list)
2068
2629
{
2069
2630
    mnu->Append(id, _("INSERT script"), _("Start query tool with INSERT script."));
2070
2631
}
2095
2656
 
2096
2657
    return view->HasInsertRule();
2097
2658
}
 
2659
 
 
2660
///////////////////////////////////////////////////////
 
2661
 
 
2662
pgScriptTimer::pgScriptTimer(frmQuery * parent) :
 
2663
  m_parent(parent)
 
2664
{
 
2665
 
 
2666
}
 
2667
 
 
2668
void pgScriptTimer::Notify()
 
2669
{
 
2670
    // Write script output
 
2671
    m_parent->writeScriptOutput();
 
2672
}
 
2673